C program to print table of number n using for/while/do while loop.

//table by for loop
#include<stdio.h>
#include<conio.h>
void main(){
int n,i;
printf("Enter an integer\n");
scanf("%d",&n);
printf("table of %d \n",n);
for(i=1;i<=10;i++){
printf("%d * %d = %d\n", n, i, n*i);
}
getch();
}

//table by while loop
#include<stdio.h>
#include<conio.h>
void main(){
int n,i=1;
printf("Enter an integer\n");
scanf("%d",&n);
printf("table of %d \n",n);
while (i<=10){
printf("%d * %d = %d\n", n, i, n*i);
i++;
}
getch();
}

//table by do while loop
#include<stdio.h>
#include<conio.h>
void main(){
int n,i=1;
printf("Enter an integer\n");
scanf("%d",&n);
printf("table of %d \n",n);
do {
printf("%d * %d = %d\n", n, i, n*i);
i++;
}while (i<=10);
getch();
}

No comments:

Post a Comment