Table of Contents
In this article, we will discuss the concept of Multiplication table program of a number in given range using C++
In this program, we are going to learn how to generate a multiplication table using many ways in C++ language.
This is done using for loop , while loop , do-while loop and method in C++ language
In this code, we will display multiplication table of a number in given range using for loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,num,range; cout<<"Enter the any number\n"; cin>>num; cout<<"Enter the range\n"; cin>>range; for(i=1; i<=range; i++){ cout << num <<" * " << i<< " = "<<num*i<<endl; } getch(); return 0; }
When the above code is executed, it produces the following result
Enter the any number 12 Enter the range 8 12 x 1 = 12 12 x 2 = 24 12 x 3 = 36 12 x 4 = 48 12 x 5 = 60 12 x 6 = 72 12 x 7 = 84 12 x 8 = 96
In this code, we will display multiplication table of a number in given range using while loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,num,range; cout<<"Enter the any number\n"; cin>>num; cout<<"Enter the range\n"; cin>>range; i=1; while(i<=range){ cout << num <<" * " << i<< " = "<<num*i<<endl; i++; } getch(); return 0; }
When the above code is executed, it produces the following result
Enter the any number 15 Enter the range 9 15 x 1 = 15 15 x 2 = 30 15 x 3 = 45 15 x 4 = 60 15 x 5 = 75 15 x 6 = 90 15 x 7 = 105 15 x 8 = 120 15 x 9 = 135
In this code, we will display multiplication table of a number in given range using do-while loop in C++ language
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { int i,num,range; cout<<"Enter the any number\n"; cin>>num; cout<<"Enter the range\n"; cin>>range; i=1; do{ cout << num <<" * " << i<< " = "<<num*i<<endl; i++; }while(i<=range); getch(); return 0; }
When the above code is executed, it produces the following result
Enter the any number 5 Enter the range 12 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50 5 x 11= 55 5 x 12= 60
In this code, we will display multiplication table of a number in given range using function in C++ language
Program 3
#include <iostream> #include <conio.h> using namespace std; void mutipication_Table(int num, int range){ int counter; for(counter=1; counter<=range; counter++){ cout<<num<<"x"<<counter<<"="<<num*counter<<endl; } } int main() { int num,range; cout<<"Enter a number: \n"; cin>>num; cout<<"Enter the range: \n"; cin>>range; mutipication_Table(num,range); getch(); return 0; }
When the above code is executed, it produces the following result
Enter the any number 12 Enter the range 4 12 x 1 = 12 12 x 2 = 24 12 x 3 = 36 12 x 4 = 48
Suggested post
Function in C++ language
Recursion in C++ language
Similar post
Code to Display multiplication table in Java
Code to Display multiplication table in C
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.