Multiplication Table in C
In this program, we will discuss how
to how to print a multiplication table of a given number.
The method we use in this program for
multiplication table in c
- C program to print multiplication table using loop
- C program to print multiplication table using array
C program to print multiplication table using loop (for loop)
|
// c program to print multiplication table of given number #include<stdio.h> #include<conio.h> void main() { int i, p, n; // taking number from user printf("\n Enter number"); scanf("%d", &n); /* use for loop from 1 to 10 to get number from 1 to 10 */ for(i=1;i<=10;i++) { p=n*i; printf("\n %d*%d = %d", n, i, p); } getch(); }
|
Output
The program takes the input of number to be print multiplication table, from the user, that value is stored in the n variable and the loop
|
for(i=1;i<=10;i++) |
Use because it gives the value of i from 1 to 10 and the part
|
p=n*i; |
Calculate the product of n and i.
If we have to print multiplication table of given number up
to 8.
We just change on the loop as
|
for(i=1;i<=8;i++) |
C program to print multiplication table using an array
|
#include<stdio.h> #include<conio.h> void main() { int num, i, j=0, p; int a[10] = {1,2,3,4,5,6,7,8,9,10}; // taking number input printf("\n Enter a number"); scanf("%d",&num); for(i=1;i<=10;i++) { /* At
initial j = 0 and the value of a[0]=1 and p=num*1
*/ p = num*a[j]; // printing multiplication table printf("\n%d*%d = %d",num,i,p); // to increase the value of j j++; } getch(); }
|
Output
First, we create an array name is with the member
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} because we generate a table up to given number *10 and the program asks
an integer from the user and it is saved on variable num.
|
for(i=1;i<=10;i++) |
And the part
|
p = num*a[j]; |
at initial print num * a[0] i.e num * 1
|
j++; |
Increase the value of j.
Also, check



0 Comments
Please do not enter any spam link on comment box