Program in c to print 1 to 100 without using loop






#include<stdio.h>

int main(){
    int num = 1;

    print(num);

    return 0;
}
int print(num){
    if(num<=100){
         printf("%d ",num);
         print(num+1);
    }
}

Output:
Sample output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100






Alogrithm:
**







28 comments:

Anonymous said...

is it possible to perform arithmatic operation using a single variable??????

Anonymous said...

no and it is posible
eg.a1,a2,a3
here a is the single variable...........

Priyanka kumari said...

Not arithmetic but unary operators like ++a, +a, !a, ~a etc.

scaryjoker said...

No need to call an external function. main() can itself be called to print numbers from 1-100:

#include
int print(int);
int num = 1;
int main(int num)
{
if(num<=100)
{
printf("%d ",num);
main(num+1);
}
return 0;
}

Unknown said...

calling main again and again is not a good idea....its more overheads...

Anonymous said...

y does writing num++; at place of num+1; does not work??

srini said...

because it is post increment it passes the current value of num and then only increments it.
meaning
num++ is written as
num=num+1
so if num is 2 and u use num++ then 2 is passed to the called function and then the value of num changes to 3

Anand said...

This is a small code for above problem.

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

Anonymous said...

do you need static? nice idea here...

Karan said...

we can also use same in main() program

sys101jimi said...

Just type 100 lines of the form
printf("1\n"); .......
printf("100");
Since we are paid by lines of code!!!

Unknown said...

Here num is the number of arguments passing from terminal.

Unknown said...

Please I want program in c to store any sentence and the convert the sentence in such way that 1st letter of every world is capital and remaining letters in lower case.

Unknown said...

Please I want program in c to store any sentence and the convert the sentence in such way that 1st letter of every world is capital and remaining letters in lower case.

Unknown said...


Write a C program to print all numbers between a and b (a and b inclusive) using a for loop

Unknown said...

nice

Unknown said...

#include
int main()
{
static int num=1;
if(num<=100)
{
printf("%d ",num);
num=num+1;
main();
}
else
getch();
return 0;
}

Unknown said...

#include
int main()
{
static int num=1;
if(num<=100)
{
printf("%d ",num);
num=num+1;
main();
}
else
getch();
return 0;
}

Unknown said...

Print the Sequence [8 12 17 24 28 33 upto 100]

Unknown said...

#include
int main()
{
static int num=1;
if(num<=100)
{
printf("%d ",num);
num=num+1;
main();
}
else
getch();
return 0;
}

Unknown said...

Errors are occuring

Unknown said...

can't we write in java for the above problem ie.,1 to 100, if yes then how

Unknown said...

#include
int main()
{
int a=1;
def:
printf("%d",a++);
if(a<=100)
goto def;
return 0;
}

Abdullah Akram said...

Write a program to find the sum of integers from 51 – 100. You are not allowed to use any
loop.

Unknown said...

1se 100 kitney baar 9 aate hai print print kaise karbaaye program bta do plz

Unknown said...

#include
int main()
{
int i=1;
while(i<=100)
{
printf("%d\n",i++);
}
return 0;

}

Unknown said...

I hai i am vikash i have a confusion
in table i want to counting number in this format so any one can solved this:
1 11 21
2 12 22
3 13 23
4 14 24
5 15 25
6 16 26
7 17
8 18
9 19
10 20
ise hi 100 tak ki counting chahta hu ki 1 to 10 row ban jaye or 11, 11, 21, 31, 41 ye column ban jaye please solve this

Unknown said...

#include
main()
{
int n,i,j,k;


for(i=1;i<=10;i++)
{
for(n=0,j=0;n<10;n++,j=10)
printf("%5d",i+j*n);
printf("\n");
}
}