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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.