C++ Program to Find the Product of Two Numbers

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

In C++, arithmetic operations like addition, subtraction, multiplication, and division can be executed. Specifically, the * operator calculates the product of two numbers. This article demonstrates writing a C++ program to find two numbers' product, highlighting the direct use of * and the alternative method of repeated addition with a for loop.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Program to Find the Product of Two Numbers Using * Operator

The product of two numbers can be evaluated easily using the * operator. The * operator is used to multiply two numbers. Let us look at the code.

Example

Below is the code to multiply two numbers using the * operator in C ++.

Output

The output of the above code is as follows.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

How Does this Program Work?

Let us break down the code and understand what each line in the above program does.

  • In the above line of code, we declared three variables, num_1, num_2, and product of double data type. The variables num_1 and num_2 are used to store the numbers to be multiplied, and the variable product will store the product of the two numbers.
  • With the help of the above lines of code, we will ask the user to enter the numbers using the cout function and store them in the variables num_1 and num_2 using the cin function.
  • This is the important line of code responsible for computing the product of two numbers. The above line uses the * operator to find the product of the two numbers.
  • This line of code is used to print the product's value stored in the product variable.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Program to Find the Product of Two Numbers Without Using * Operator

Multiplication is also known as repeated addition. We can find the product without using the * operator. Let us take a simple example of 2X4=82 X 4 = 8, i.e., two fours are eight. This means that we are adding 2's for 4 times. For example, the product of 5X35X3 can be calculated using the repeated addition as 5+5+5=155+5+5 = 15. We can use the same logic and find the product of two numbers without using the * operator.

Example

The following code is used to calculate the product of two numbers without using the * operator.

Output

The output of the above code is as follows.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

How Does this Program Work?

Let us break down the code and understand what each line in the above program does.

  • In the above lines of code, we will declare the variables num_1 and num_2 to store the input numbers and the product variable to store the product of two numbers. Using the function cin and cout, we will ask the user to enter the numbers and store them in the variables num_1 and num_2. We will also initialize the value of the product variable to 0.
  • We will use the for loop to perform the repeated addition of the number. We will add num_1 to the product variable num_2 times to get the product of two numbers.
  • This line of code is used to print the product value stored in the product variable.

Conclusion

  • Multiplication is the repeated addition of a number.
  • The product of two numbers can be easily calculated using the * operator.
  • The product of two numbers can be calculated without using the * operator by repeated addition of the number.