Friday, July 31, 2009

How to Print 1 to N without recursion,loops,gotos,labels.....

I need the code in C...

How to Print 1 to N without recursion,loops,gotos,labels.....
The first way I can think of is using if statements.





printf("1\n");


if (n%26gt;1) {


printf("2\n");


if (n%26gt;2) {


printf("3\n");


if (n%26gt;4) {


printf("4\n");


// until the maximum value of n is reaches


}


}


}





Given the limitations of no loops means that you will have 2N lines of code. However this method might be faster than a loop in code execution if you ignore the performance hit the increased code size may causes.





And another method is:


printf("1 to N");
Reply:In short, how do you do something repeatedly without using any normal control structures? I wouldn't waste my time on such a task. Any instructor telling you to do that is an idiot. It's possible with an insane amount of typing and a program structure that no one should learn.





If you want to repeat a piece of code N times, you use a loop.





Some instructors think it's good to "think out of the box" by getting you to do something in a completely idiotic way. Anything you do here will have to be completely unlearned when you actually try to write software.



myspace quizzes

No comments:

Post a Comment