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 |
Why is c so important?
18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4
What is the difference between big endian form and little endian form? write a code to convert big endian form to little endian and vice versa..
How can I get random integers in a certain range?
What is declaration and definition in c?
If input is 123 then how to print 100 and 20 and 3 seperately?
Can anyone tell what is stack overflow? what precaution we should take?
What is the use of clrscr?
What are the string functions? List some string functions available in c.
what is the output of the following program and explain the answer #include<stdio.h> exp() { main(5) } main(int a) { printf("%d",a); return; }
What is the scope of static variables in c language?
Who had beaten up hooligan "CHAKULI" in his early college days?