multiplication table
Table of Contents
In this article, we will discuss the concept of C program to Generate multiplication table.
In this program, we are going to learn how to generate a multiplication table in C programming language.
This is done using for loop , while loop , do-while loop , function and recursion
In this program, we will display multiplication table of given number using for loop in C language.
Program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,i;
printf("Enter an integer\n");
scanf("%d",&num);
for(i=1; i<=10; i++){
printf("%d * %d = %d\n",num,i,num*i);
}
getch();
return 0;
}
When the above code is executed,it produces the following result
Enter an integer 12 12 * 1 = 12 12 * 2 = 24 12 * 3 = 36 12 * 4 = 48 12 * 5 = 60 12 * 6 = 72 12 * 7 = 84 12 * 8 = 96 12 * 9 = 108 12 * 10 = 120
In this program, we will display multiplication table of given number using while loop in C language.
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,i;
printf("Enter an integer\n");
scanf("%d",&num);
i=1;
while(i<=10){
printf("%d * %d = %d\n",num,i,num*i);
i++;
}
getch();
return 0;
} When the above code is executed,it produces the following result
Enter an integer 15 15 * 1 = 15 15 * 2 = 30 15 * 3 = 45 15 * 4 = 60 15 * 5 = 75 15 * 6 = 90 15 * 7 = 105 15 * 8 = 120 15 * 9 = 135 15 * 10 = 150
In this program, we will display multiplication table of given number using do-while loop in C language.
Program 3
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,i;
printf("Enter an integer\n");
scanf("%d",&num);
i=1;
do{
printf("%d * %d = %d\n",num,i,num*i);
i++;
}while(i<=10);
getch();
return 0;
} When the above code is executed,it produces the following result
Enter an integer 8 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 8 * 9 = 72 8 * 10 = 80
In this program, we will display multiplication table of given number using function in C language.
Program 4
#include <stdio.h>
#include <stdlib.h>
void mulTable(int);
int main()
{
int num;
printf("Enter a positive number\n");
scanf("%d",&num);
printf("\nMutiplication table for %d is\n",num);
mulTable(num);
getch();
return 0;
}
void mulTable(int num)
{
int count;
for(count=1; count<=12; count++ ){
printf("%d x %d = %d\n",num,count,num*count);
}
}
When the above code is executed,it produces the following result
In this program, we will display multiplication table of given number using recursion in C language
Program 5
#include <stdio.h>
#include <stdlib.h>
void mulTable(int,int);
int main()
{
int num,i=1;
printf("Enter a positive number\n");
scanf("%d",&num);
printf("\nMutiplication table for %d is\n",num);
mulTable(num,i);
getch();
return 0;
}
void mulTable(int num,int i)
{
if(i>10){
return 0;
}
else
{
printf("%d*%d=%d\n",num,i,num*i);
return mulTable(num,i+1);
}
}
When the above code is executed,it produces the following result
Suggested post
Similar post
Program to Display multiplication table in Java
Program to Display multiplication table in C
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.