In this article, you will learn to generate the multiplication table of a number.
Examples :
Input : 2 Output : 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 2 * 10 = 20 Input : 8 Output : 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50
Implementation :
1. Using for loop :
// C program to print multiplication table of a number #include <stdio.h> int main() { // take input int num = 9 ; int i; for(i=1; i<=10; i++) { printf("%d * %d = %d\n", num, i, (num*i)); } // successful completion return 0; }
Output :
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90
Note –
- This program above computes the multiplication table up to 10 only. But we can modify the upto number, if we want, in place of 10. Either less in range or more range than 10.
- We can also write this program using ‘while loop’, ‘do while loop’, ‘using function’, and ‘using recursion’, if we want to do.
Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.