multiply

Cpp program to multiply two numbers using function

Cpp program to multiply two numbers using function

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

Cpp program to multiply two integer numbers

This program can have important following steps to completion

  • Function declaration or prototype
  • essential variable declaration
  • read the number from the user to store in the variable
  • Function definition with the return value
  • calling the function
  • Display result on the screen

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.

Cpp program to multiply two floating point numbers

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

Operator in C++ language

Function in C++ language

Data type in C++ language

Java program to calculate sum in array elements
Java program to multiply two numbers using method
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago