Write a C program to print 1 2 3 ... 100 without using
loops?

Answers were Sorted based on User's Feedback



Write a C program to print 1 2 3 ... 100 without using loops?..

Answer / sutanu

void main ()
{
static int i;
if (i <= 100)
{
printf ("%d\n", i);
i++;
main ();
}
}

Is This Answer Correct ?    53 Yes 15 No

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

Answer / vivek

void main()
{
int i=1;
if(i<=100)
printf("%d",i);
continue;
getch();
}

Is This Answer Correct ?    6 Yes 2 No

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Write a C program to print 1 2 3 ... 100 without using loops?..

Answer / maxerp

In general, by using recursion, since it is the only
alternative to looping constructs

Is This Answer Correct ?    11 Yes 12 No

Write a C program to print 1 2 3 ... 100 without using loops?..

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

Post New Answer

More C Interview Questions

Why does this code crash?

0 Answers  


15.what is the disadvantage of using macros? 16.what is the self-referential structure? 17.can a union be self-referenced? 18.What is a pointer? 19.What is the Lvalue and Rvalue? 20.what is the difference between these initializations? 21.Char a[]=”string”; 22.Char *p=”literal”; 23.Does *p++ increment p, or what it points to?

1 Answers  


Explain how can I remove the trailing spaces from a string?

0 Answers  


Here is a good puzzle: how do you write a program which produces its own source code as output?

0 Answers  


to get a line of text and count the number of vowels in it

3 Answers   Satyam,






difference between i++* and *++i

6 Answers   IBM,


what is use#in c

3 Answers  


program for comparing 2 strings without strcmp()

4 Answers  


Is null a keyword in c?

0 Answers  


What does dm mean sexually?

0 Answers  


Program to find the absolute value of given integer using Conditional Operators

6 Answers   N Tech,


consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is

4 Answers   TCS,


Categories