For, While and Do-While Loop Program in C

For Loop Program

#include <stdio.h>
void main()
{
int number;
for (number=1; number<=10; number++)
{
printf(“%d”,number);
}
}

Output

1 2 3 4 5 6 7 8 9 10

While Loop Program

#include <stdio.h>
int main()
{
int number=1;
while(number<=10)
{
printf(“%dt”,number);
number++;
}
}

Output

1 2 3 4 5 6 7 8 9 10

Do-While Loop Program

#include <stdio.h>
int main()
{
int number=5;
do
{
printf(“%dn”,number);
number++;
}
while(number>10);
printf(“Num is not greater than 10”);
}

Output

5
Num is not greater than 10