In this tutorial, we will discuss the Cpp program to multiply two numbers using the function
In this topic, we will learn a simple concept of how to multiply two integers using the function in the C++ programming language
already we will know the same concept using the operator in a simple way.
If you want to know, click here C++ program to multiply two numbers
This program can have important following steps to completion
Program 1
#include <iostream> #include <conio.h> using namespace std; int multiply(int x, int y);//function declaration or prototype int main() { int num1; //variable for store first numbers int num2; //variable for store second numbers int product; //variable for store result of product //read numbers cout << "Enter the first numbers" << endl; cin>>num1; //stored first number- get input from user cout << "Enter the second numbers" << endl; cin>>num2; //stored second number- get input from user product=multiply(num1, num2);//calling function and stored returning the result by function; //print product of numbers cout<<"Product of two numbers "<<product<<endl; getch(); return 0; } //function definition int multiply(int x, int y) { return (x*y); //return the product result to main }
When the above code is compiled and executed, it produces the following results
Enter the first numbers 45 Enter the second numbers 34 product of two numbers 1530
In this program, the user is asked to enter two numbers(integer numbers). then it calculating product of those numbers and display on the screen
Here, when the user enters the numbers, the first number stored in variable num1 and the second number stored the variable num2. Then, the product of the numbers is stored in the variable product.
Program 1
#include <iostream> #include <conio.h> using namespace std; float multiply(float x, float y);//function declaration or prototype int main() { float num1; //variable for store first numbers float num2; //variable for store second numbers float product; //variable for store result of product //read numbers enterd from user cout << "Enter the first numbers" << endl; cin>>num1; //stored first number- get input from user cout << "Enter the second numbers" << endl; cin>>num2; //stored second number- get input from user product=multiply(num1, num2);//calling function and stored returning the result by function; //print product of numbers cout<<"Product of two numbers "<<product<<endl; getch(); return 0; } //function definition float multiply(float x, float y) { return (x*y); //return the multiplication result to main }
When the above code is compiled and executed, it produces the following results
Enter the first number 12.34 Enter thes second number 21.43 the product of two numbers 264.446
In this program, the user is asked to enter two numbers(floating point numbers). then it calculating product of those numbers and display on the screen
Here, when the user enters the numbers, the first number stored in variable num1 and the second number stored the variable num2. Then, the product of the numbers is stored in the variable product.
Suggested for you
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…