C program to print counting from m to n using for/while/ do while loop

//counting by for loop
#include<stdio.h>
#include<conio.h>
void main(){
int i,m,n;
clrscr();
printf("Enter range of counting m and n \n");
scanf("%d%d",&m,&n);
printf("Counting from %d to %d\n",m,n);
for(i=m;i<=n;i++){
printf("%d ",i);
if (i%10==0) printf("\n");
}
getch();
}

//counting by while loop
#include<stdio.h>
#include<conio.h>
void main(){
int i,m,n;
clrscr();
printf("Enter range of counting m and n e\n");
scanf("%d%d",&m,&n);
printf("Counting from %d to %d\n",m,n);
i=m;
while (i<=n){
printf("%d ",i);
if (i%10==0) printf("\n");
i++;
}
getch();
}

//counting by do while loop
#include<stdio.h>
#include<conio.h>
void main(){
int i,m,n;
clrscr();
printf("Enter range of counting m and n\n");
scanf("%d%d",&m,&n);
printf("Counting from %d to %d\n",m,n);
i=m;
do {
printf("%d ",i);
if (i%10==0) printf("\n");
i++;
}while (i<=n);
getch();
}

No comments:

Post a Comment