Contact Learn C
Copy

Program 2 : To print from 1 to 100 numbers.

Program 2 :

#include<stdio.h>

main()

{

int i;

for(i=1;i<=100;i++)

{

printf("%d\n",i);

}

}
Output:-
1
2
3
4
5
.
.
.
.
.
100
Explanation :
1.)initialises i as an integer. 2.)Now i=1 and is lesser than 100 so condition satisfies and prints the value of i which is 1.
3.)Now i is incremented to '2' and again it is less than 100 so condition satisfies and prints the value of i which is '2'.
4.)It goes like that until i is equal to 100 and it is equal to 100 so it prints 100 than the value of i is incremented to 101 which dissatisfies the condition causing to come out of the loop.
5. As there are no statements out of the loop the program terminates.

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide