Home »
C programs »
C looping programs
C program to read an integer and print its multiplication table
This program is asked through comment
Question
Using while or do while loop: wap to read any integer number and print its multiplication table
Answer/Solution
In this program, we are reading an integer number and printing its multiplication table, we are implementing the program using for, while and do while (through all loops).
Logic
- Read an integer number
- Take a loop counter and initialize it with 1
- Run a loop from 1 to 10
- Print the multiplication of input number and loop counter
- Increase the loop counter
Complete program using while loop
#include <stdio.h>
int main()
{
int num; /*to store number*/
int i; /*loop counter*/
/*Reading the number*/
printf("Enter an integer number: ");
scanf("%d",&num);
/*Initialising loop counter*/
i=1;
/*loop from 1 to 10*/
while(i<=10){
printf("%d\n",(num*i));
i++; /*Increase loop counter*/
}
return 0;
}
Output
Enter an integer number: 12
12
24
36
48
60
72
84
96
108
120
Code using do while loop
/*Initialising loop counter*/
i=1;
/*loop from 1 to 10*/
do{
printf("%d\n",(num*i));
i++; /*Increase loop counter*/
}while(i<=10);
Code using for loop
for(i=1;i<=10;i++){
printf("%d\n",(num*i));
}
C Looping Programs »