Print 1 to 100 integers in C programming language:
#include<stdio.h>
main()
{
int i;
for(i=1;i<=100;i++)
{
printf("%d\n",i);
}
}
Output:
1
2
3
4
5
6
7
8
9
.
.
.
.
.
.
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 isincremented 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.