In this article, we are going to learn how to print a table of numbers from 1 to 20e can print the mathematical table of any number. We will learn this with two programs first we will generate tables of numbers from 1 to 20. In the second example, we will print the table of any number which user wants.
1.C program to print table of numbers from 1 to 20
In this example, we are printing the table of numbers from 1 to 20. You can expand this program for any number of table range.
#include <stdio.h>
int main()
{
int num;
for(int i=1; i<=20; i++)
{
num= i;
for(int j=1; j<=10; j++)
{
printf("%3d\t",(num*j));
}
printf("\n");
}
return 0;
}
Output
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
11 22 33 44 55 66 77 88 99 110
12 24 36 48 60 72 84 96 108 120
13 26 39 52 65 78 91 104 117 130
14 28 42 56 70 84 98 112 126 140
15 30 45 60 75 90 105 120 135 150
16 32 48 64 80 96 112 128 144 160
17 34 51 68 85 102 119 136 153 170
18 36 54 72 90 108 126 144 162 180
19 38 57 76 95 114 133 152 171 190
20 40 60 80 100 120 140 160 180 200
2.C program to print table of any numbers
n this example, we are printing the table of a number given by the user. We are printing the table in the form of
table with multiple of max 10.
#include <stdio.h>
int main()
{
int i,j;
int num;
printf("Please enter the Number for which you want the table: ");
scanf("%d",&num);
printf("The Table for the asked number is:\n ");
for(i=1; i<=10; i++)
{
printf(" %d",num); printf(" x "); printf(" %d",i); printf(" ="); printf(" %d",i*num);
printf("\n");
}
return 0;
}
Output
Please enter the Number for which you want the table: 6
The Table for the asked number is:
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60