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 using 5 ways in C++ language.
This is done using for loop , while loop , do-while loop , method and recursion
In this program, we will display multiplication table of given number using for loop in C++ language
Program 1
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num;
cout << "Enter an integer!" << endl;
cin>>num;
for(int i=1; i<=10; i++){
cout<<num<<" * "<<i<<" = "<<num*i << endl;
}
getch();
return 0;
} When the above code is executed , it produces the following result
Enter an integer 13 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 = 127 13 * 10 = 130
In this program, we will display multiplication table of given number using while loop in C++ language
Program 2
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num;
cout << "Enter an integer!" << endl;
cin>>num;
int i=1;
while(i<=10){
cout<<num<<" * "<<i<<" = "<<num*i << endl;
i++;
}
getch();
return 0;
} When the above code is executed , it produces the following result
Enter an integer 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
In this program, we will display multiplication table of given number using do-while loop in C++ language
Program 3
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num;
cout << "Enter an integer!" << endl;
cin>>num;
int i=1;
do{
cout<<num<<" * "<<i<<" = "<<num*i << endl;
i++;
} while(i<=10);
getch();
return 0;
} When the above code is executed , it produces the following result
Enter an integer 11 11 * 1 = 11 11 * 2 = 22 11 * 3 = 33 11 * 4 = 44 11 * 5 = 55 11 * 6 = 66 11 * 7 = 77 11 * 8 = 88 11 * 9 = 99 11 * 10 =110
In this program, we will display multiplication table of given number using function
Program 4
#include <iostream>
#include <conio.h>
using namespace std;
void mulTable(int);//function prototype
int main()
{
int num;
cout<<"Enter a positive number\n";
cin>>num;
cout<<"\nMutiplication table for "<<num<< "is\n";
mulTable(num);//function call
getch();
return 0;
}
void mulTable(int num)//function definition
{
int i;
for(i=1; i<=12; i++ ){
cout<<num<<" * "<<i<<" = "<<num*i<<"\n";
}
} When the above code is executed , it produces the following result
In this program, we will display multiplication table of given number using recursive function
Program 5
#include <iostream>
#include <conio.h>
using namespace std;
int mulTable(int,int);//function prototype
int main()
{
int num,i=1;
cout<<"Enter a positive number\n";
cin>>num;
cout<<"\nMutiplication table for "<<num<< " is\n";
mulTable(num,i);//function call
getch();
return 0;
}
int mulTable(int num,int i)//function definition
{
if(i>10){
return 0;
}
else
{
cout<<num<<" * "<<i<<" = "<<num*i << endl;
return mulTable(num,i+1);
}
}
When the above code is executed , it produces the following result
Suggested post
Function in C++ language
Recursion in C++ language
Similar post
Program to Display multiplication table in Java
Program to Display multiplication table in C
Program to Display multiplication table in C++
Program to Display multiplication table in Python
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.