Write a program that prints a multiplication table for a given number and the number of rows in the table. For example, for a number 5 and rows = 3, the output should be:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15 ……………..
#include <stdio.h>
void main()
{
int n, j,r=0;
//clrscr();
printf("\n Enter a number:\n ");
scanf("%d",&n);
printf("\n Enter number of rows:\n ");
scanf("%d",&r);
printf("\n Multiplication table for a given= %d", n);
printf("\n The number of rows in the table=%d", r);
for(j=1;j<=r;j++)
{
printf("\n %d * %d = %d ", n, j, n*j);
}
//getch();
}
OUTPUT:
Enter a number:
7
Enter number of rows:
5
Multiplication table for a given= 7
The number of rows in the table=5
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
Comments
Post a Comment