
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Multiply Two Numbers
Multiplication of two numbers a and b yields their product. Value of a is added as many times as the value of b to get the product of a and b.
For example.
5 * 4 = 20 7 * 8 = 56 9 * 9 = 81
Program to Multiply two Numbers using * Operator
A program to multiply two numbers using the * operator is given as follows −
Example
#include <iostream> using namespace std; int main() { int a = 6, b = 8; cout<<"Product of "<<a<<" and "<<b<<" is "<<a*b<<endl; return 0; }
Output
Product of 6 and 8 is 48
In the above program, the product of a and b is simply displayed using the * operator. This is demonstrated by the following code snippet.
cout<<"Product of "<<a<<" and "<<b<<" is "<<a*b<<endl;
Program to Multiply two Numbers Without Using * Operator
A program to multiply two numbers without using the * operator is given as follows −
Example
#include<iostream> using namespace std; int main() { int a=7, b=8, product=0; for(int i=1; i<=b; i++) product = product + a; cout<<"The product of "<<a<<" and "<<b<<" is "<<product<<endl; return 0; }
Output
The product of 7 and 8 is 56
In the above program, a for loop is used to add the value of a total of b times. This yields the product of a and b.
This is demonstrated by the following code snippet.
for(int i=1; i<=b; i++) product = product + a;
After this, the product of a and b is displayed. This is shown as follows −
cout<<"The product of "<<a<<" and "<<b<<" is "<<product<<endl;
Advertisements