Table of a number
C program to print the table of a number entered by the user.
In Method 1, multiplication table upto 10 is generated and in Method 2 there is the little modification of the program to generate the multiplication table up to a specific range (where range is a positive integer entered by the user).
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
printf("Enter the number whose table is to be calculated\t:");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
printf("%d * %d = %d\n",num,i,num*i);
}
getch();
}
Output
Enter the number whose table is to be calculated :7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num, i, range;
printf("Enter the number whose table is to be calculated\t:");
scanf("%d",&num);
printf("Enter the range\t:");
scanf("%d",&range);
for(i=1;i<=range;i++)
{
printf("%d * %d = %d\n",num,i,num*i);
}
getch();
}
Output
Enter the number whose table is to be calculated :13
Enter the range :12
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 117
13 * 10 = 130
13 * 11 = 143
13 * 12 = 156