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 |
hi, which software companys will take,if d candidate's % is jst 55%?
What is non linear data structure in c?
Explain pointer. What are function pointers in C?
what does ‘#include’ mean?
Write a program which has the following seven functions. The functions should be: • main() this calls the other 6 functions • fget_long() a function which returns a long data type from a file • fget_short() a function which returns a short integer variable from a file • fget_float() a function which returns a floating point variable from a file • fprt_long() a function which prints its single, long argument into a file • fprt_short() a function which prints its single, short argument into a file • fprt_float() a function which prints its single, floating point argument into a file. You should use fscanf() to get the values of the variables from the input (the file) and fprintf() to print the values to the other file. Pay attention to using the correct format for each of the data types.
If null and 0 are equivalent as null pointer constants, which should I use?
In how much time you will write this c program? Prime nos from 1 to 1000
How are pointers declared in c?
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types?
Is a house a mass structure?
What is the difference between scanf and fscanf?
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.