Thursday, May 2, 2013

C Program to Print 1-100 Using Do-While Loop

The C Program given below will print the numbers between 1 to 100. I have used Do-While Loop to print those numbers. But it is also possible with both For Loop and While Loop.

In this program a variable i is initialized with 1 using the line int i=1;. That's why the program will print 1 at the first of all during executing the 5th line printf("%d, ",i); and in the 6th line the value of i will be increased by 1.

In the condition there is written while(i<=100);. That's why the loop will continue till the value of i is 100.
#include<stdio.h>
void main(){
int i=1;
do{
printf("%d, ",i);
i++;
}while(i<=100);
}

Do-While Loop, Uses of Loop




No comments:

Post a Comment