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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

1 month ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

1 month ago