QUESTION:- Write a program in C to display the multiplication table vertically from 1 to n.
1*1 2*1 3*1 4*1
1*2 2*2 3*2 4*2
1*3 2*3 3*3 4*3
1*4 2*4 3*4 4*4
1*5 2*5 3*5 4*5
.
.
.
.
1*10 2*10 3*10 4*10
#include <stdio.h>
#include <conio.h>
void
main()
{
int a;
printf("enter a value of a: ");
scanf("%d", &a);
// row
for (int i = 1; i <= 10; i++)
{
// column
for (int j = 1; j <= a; j++)
{
if (j <= a - 1) // 1 <= (4-1) 3
{
printf("%d X %d = %d\t", i, j, (i * j));
}
else
{
printf("%d X %d = %d\t", i, j, (i * j));
}
}
printf("\n");
}
getch();
}
OUTPUT
enter a value of a: 4
1 X 1 = 1 1 X 2 = 2 1 X 3 = 3 1 X 4 = 4
2 X 1 = 2 2 X 2 = 4 2 X 3 = 6 2 X 4 = 8
3 X 1 = 3 3 X 2 = 6 3 X 3 = 9 3 X 4 = 12
4 X 1 = 4 4 X 2 = 8 4 X 3 = 12 4 X 4 = 16
5 X 1 = 5 5 X 2 = 10 5 X 3 = 15 5 X 4 = 20
6 X 1 = 6 6 X 2 = 12 6 X 3 = 18 6 X 4 = 24
7 X 1 = 7 7 X 2 = 14 7 X 3 = 21 7 X 4 = 28
8 X 1 = 8 8 X 2 = 16 8 X 3 = 24 8 X 4 = 32
9 X 1 = 9 9 X 2 = 18 9 X 3 = 27 9 X 4 = 36
10 X 1 = 10 10 X 2 = 20 10 X 3 = 30 10 X 4 = 40
0 Comments