Multiplication Table in C
Displaying table up to 10
#include <stdio.h>
int main() {
int num, i = 1;
printf("
Enter any Number:");
scanf("%d", &num);
printf("Multiplication table of %d: ", num);
while (i <= 10) {
printf("
%d x %d = %d", num, i, num * i);
i++; }
return 0;
}
Output:
Enter any 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
Displaying multiplication table up to n numbers:
#include <stdio.h>
int main() {
int n, i, range;
printf("Enter an integer: ");
scanf("%d", &n);
// prompt user for positive range
do {
printf("Enter the range (positive integer): ");
scanf("%d", &range);
} while (range <= 0);
for (i = 1; i <= range; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
Output:
Enter an integer: 12
Enter the range (positive integer): -8
Enter the range (positive integer): 8
12 * 1 = 12
12 * 2 = 24
12 * 3 = 36
12 * 4 = 48
12 * 5 = 60
12 * 6 = 72
12 * 7 = 84
12 * 8 = 96