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:
**







27 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...........

ritesh kumar 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;
}

Hanish Maghu 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 Barnwal 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...

KIRAN JADHAV 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!!!

Pankaj Aagjal said...

Here num is the number of arguments passing from terminal.

Bilal Sultan Al-Samaee 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.

Bilal Sultan Al-Samaee 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.

ritu lia said...


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

Jahirul Islam Monir said...

nice

shantanu jain said...

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

shantanu jain said...

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

saim kamran said...

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

Karankumar Kk said...

tq

Karankumar Kk said...

no need of "int print(int);"

sharvan raj said...

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

hemanth monu said...

Errors are occuring

srikanth chowdary said...

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

Aswin Bupathi 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.

Shivam Gupta said...

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