#include <stdio.h>
/* C program to print numbers from 1 to 10 using while loop */
int main()
{
int j = 1;
printf("Series....:\n");
while(j <= 10)
{
printf("%d ", j);
j++;
}
printf("\n");
return 0;
}
Output:
Series........:
1 2 3 4 5 6 7 8 9 10
Program Explanation:
In the above program variable j is declared as integer variable and initialized to number 1.
printf("Series....:\n");
display Series........
control jumps to while loop and test the condition while(j<=10).
i.e. while(1<10) which results in true, printf("%d ", j); statement inside body of loop executes and display value of j .i.e. 1 .
The value of j is incremented by 1, now j becomes 2 i.e. j=2.
Control again jumps to while and test the condition which is true.
Post that executes the body of loop , shows output 2 after that value of j is incremented by 1.
The process continues while the value of j is less than or equal. (while (j<=10))