Cpp Program To Multiply Two Numbers Using Function

In this tutorial, we will discuss the C++ 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.
Source Code: 

#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
}

Post a Comment

 
Top