this problem was discussed some time before on this group.... i am picking up a solution discussed there which you would love to see
int i=1; #define PRINT1 cout<<i++<<endl; #define PRINT2 PRINT1 PRINT1 #define PRINT4 PRINT2 PRINT2 #define PRINT8 PRINT4 PRINT4 #define PRINT16 PRINT8 PRINT8 #define PRINT32 PRINT16 PRINT16 #define PRINT64 PRINT32 PRINT32 int main() { //as 100 = (1100100); we need to use PRINT64, PRINT32, and PRINT4 PRINT64; PRINT32; PRINT4; } This will print 1 to 100. You can use this code to print from 1 to x (x<=128). You can extend it to larger numbers, by adding PRINT128, PRINT256...etc. i appreciate the radikha's solution...it was discussed there also and is better :) On Fri, Jun 10, 2011 at 9:15 AM, Radhika Renganathan <radi.coo...@gmail.com>wrote: > sorry i meant 'constructor' ! > > On Fri, Jun 10, 2011 at 9:40 PM, Radhika Renganathan < > radi.coo...@gmail.com> wrote: > >> we can declare a class with construction printing value >> >> class A >> { >> private: >> static int i; >> public: >> A() >> { >> cout<<++i <<endl; >> } >> }; >> A::i=0; >> main() >> { >> int n=5; >> A ob[n]; >> } >> this will print from 1 to 5 >> >> am i right? >> >> >> On Fri, Jun 10, 2011 at 9:30 PM, Navneet Gupta <navneetn...@gmail.com>wrote: >> >>> Using recursion would be like using loops only. Also i believe the >>> recursion used would be tail recursion and one can change tail recursion to >>> loop based non recursive method. >>> >>> Okay, giving all a hint. Think classes and objects. >>> >>> >>> On Fri, Jun 10, 2011 at 9:26 PM, Navneet Gupta <navneetn...@gmail.com>wrote: >>> >>>> No. >>>> >>>> >>>> On Fri, Jun 10, 2011 at 9:26 PM, nagajyothi gunti < >>>> nagajyothi.gu...@gmail.com> wrote: >>>> >>>>> >>>>> Can "goto" statement be used? >>>>> >>>>> On Fri, Jun 10, 2011 at 11:42 AM, Navneet Gupta <navneetn...@gmail.com >>>>> > wrote: >>>>> >>>>>> Take n from user and print 1 to n. No loops like for/while/do-while >>>>>> are allowed to use. >>>>>> >>>>>> --Navneet >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Algorithm Geeks" group. >>>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>>> To unsubscribe from this group, send email to >>>>>> algogeeks+unsubscr...@googlegroups.com. >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Jyothi >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> algogeeks+unsubscr...@googlegroups.com. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> --Navneet >>>> >>>> >>> >>> >>> -- >>> --Navneet >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> .... radhika .. :) >> > > > > -- > .... radhika .. :) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.