C Program to Display Multiplication Table
Using for Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using for loop
Example
#include <stdio.h>
int main() {
int table = 9;
int length = 10;
int i = 1;
printf("Multiplication table: %d", table);
for(i=1; i<=length; i++)
printf("\n%d * %d = %d", i, table, i * table);
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Using while Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using while loop
Example
#include <stdio.h>
int main() {
int table = 9;
int length = 10;
int i = 1;
printf("Multiplication table: %d", table);
while(i <= length){
printf("\n%d * %d = %d", i, table, i * table);
i++;
}
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Using do while Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using do while loop
Example
#include <stdio.h>
int main() {
int table = 9;
int length = 10;
int i = 1;
printf("Multiplication table: %d", table);
do{
printf("\n%d * %d = %d", i, table, i * table);
i++;
}while(i <= length);
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Display Customized Table
In the following example, we will display the table according to the given table number and table length.
Example
#include <stdio.h>
int main() {
int table, length;
int i = 1;
printf("Enter the table number: ");
scanf("%d", &table);
printf("Enter the length: ");
scanf("%d", &length);
printf("\nMultiplication table: %d", table);
for(i=1; i<=length; i++)
printf("\n%d * %d = %d", i, table, i * table);
return 0;
}
Output
Enter the table number: 7
Enter the length: 10
Multiplication table: 7
1 * 7 = 7
2 * 7 = 14
3 * 7 = 21
4 * 7 = 28
5 * 7 = 35
6 * 7 = 42
7 * 7 = 49
8 * 7 = 56
9 * 7 = 63
10 * 7 = 70
Reminder
Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.
We are working to cover every Single Concept in C.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Meet the Author