This C Language program prints numbers from 1 to 5 using for loop, do-while loop, and while loop in easy steps.
Change the counter value in case the user wants to print n numbers.
#include<stdio.h>
int main(){
int i=1,j=1,k=1;
//print number series using do while loop
do{
printf("%d \t",i);
i++;
}while(i<=5);
printf("\n");
//print number series using while loop
while(j<=5)
{
printf("%d\t",j);
j++;
}
//print number series using for loop
printf("\n");
for(int k=1;k<=5;k++)
printf("%d\t",k);
return 0;
}
Output
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
By changing variable values one can print n number series in C language using three different loops.