Write a C program to print the multiplication table of a number
Description: Take a number as input and print its multiplication table from 1 to 10.
Hint:
- Use a
forloop from 1 to 10 and printn * iin each round.
C program to print a multiplication table
#include <stdio.h>
int main(void) {
int n;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", n, i, n * i);
}
return 0;
}
Output:
Output of the above program is
Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
How it works
- The loop variable
igoes from 1 to 10. - In each round the program prints the number, the multiplier and the product.
Read C For Loop.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |