Write a C program to print 1 2 3 ... 100 without using
loops?
Answers were Sorted based on User's Feedback
Answer / sutanu
void main ()
{
static int i;
if (i <= 100)
{
printf ("%d\n", i);
i++;
main ();
}
}
Is This Answer Correct ? | 53 Yes | 15 No |
Answer / gunabalan
void main()
{
int i=1;
e:
printf("%d\t",i);
i++;
if(i<=100)
goto e;
}
Is This Answer Correct ? | 36 Yes | 12 No |
Answer / lakshmipraba
#include<stdio.h>
int i;
void main()
{
if(i<=100)
{
printf("%d ",i);
i++;
main();
}
if(i>100)
exit(0);
}
Is This Answer Correct ? | 14 Yes | 3 No |
Answer / vivek
void main()
{
int i=1;
if(i<=100)
printf("%d",i);
continue;
getch();
}
Is This Answer Correct ? | 6 Yes | 2 No |
Answer / neha
int i;
void main(void)
{
if(i<=100)
printf("%d\n", i);
i++;
main();
getch();
}
Is This Answer Correct ? | 29 Yes | 26 No |
Answer / uma maheswari
#include<stdio.h>
#include<conio.h>
int i=1;
void main()
{
i<=100 ? printf("%d\n",i) : getch(); //conditional operator
i++;
main(); //recursive calling of main() function
}
Is This Answer Correct ? | 10 Yes | 7 No |
Answer / sagar
we can also create such a program without using loops and if
statement too ...
void main()
{
int i,n;
clrscr();
A:
printf("%d",i);
n=i++;
switch(n)
{
case 100: break;
default : goto A;
}
getch();
}
Is This Answer Correct ? | 9 Yes | 7 No |
Answer / harsha
#include<stdio.h>
int i=0;
void main()
{
if(i==0)
clrscr();
if(i<100) {
printf("%d \t",++i);
main(); }
else {
getch();
exit(0); }
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / maxerp
In general, by using recursion, since it is the only
alternative to looping constructs
Is This Answer Correct ? | 11 Yes | 12 No |
Answer / vivek
#include<stdio>
void main()
{
int i=1;
if(i<=100)
printf("%d",i);
i++;
continue;
getch;
}
Is This Answer Correct ? | 2 Yes | 3 No |
in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures
What is a program flowchart and how does it help in writing a program?
write a code for large nos multilication (upto 200 digits)
What is the difference between if else and switchstatement
Why should I use standard library functions instead of writing my own?
How do we declare variables in c?
What is extern storage class in c?
What is c standard library?
What is union and structure?
What is meant by errors and debugging?
Difference between null pointer and dangling pointer?
c program to add and delete an element from circular queue using array