| PREV |
Programs |
NEXT |
| |
(85 / 301) |
|
|
|
|
Write a program to print numbers from 1 to 100 without using loops!
|
Another "Yeah, I am a jerk, kick me! kind of a question. I simply dont know why they ask these questions.
Nevertheless, for the benefit of mankind...
Method1 (Using recursion)
void printUp(int startNumber, int endNumber)
{
if (startNumber > endNumber)
return;
printf("[%d]\n", startNumber++);
printUp(startNumber, endNumber);
}
Method2 (Using goto)
void printUp(int startNumber, int endNumber)
{
start:
if (startNumber > endNumber)
{
goto end;
}
else
{
printf("[%d]\n", startNumber++);
goto start;
}
end:
return;
}
|
| PREV |
COMMENTS INDEX PRINT |
NEXT |
Last updated:
November 3, 2005
www.cracktheinterview.com - Your destination for the most common IT interview questions, answers, frequently asked interview questions (FAQ), C Programs, C Datastructures for technical interviews conducted by the top IT companies around the world!
|
|
|