Categories: C++

Program To Perform All Arithmetic Operations Using Functions

For two variables entered by the user, we must create separate functions for addition, subtraction, division, and multiplication.

Program Code:


#include <iostream>
using namespace std;
int addition(int ,int);
int subtraction(int, int);
int multiplication(int, int);
float division(int , int);
int modulus(int , int );

int addition(int num1, int num2)
{
    int sum = num1 + num2;
    return sum;
}

int subtraction(int num1, int num2)
{
    return num1 - num2;
}

int multiplication(int num1, int num2)
{
    return num1 * num2;
}

float division(int num1, int num2)
{
    return num1 / num2;
}

int mod(int num1, int num2)
{
    return num1 % num2;
}

int main()
{   
    int a, b;
    
    cout<<("Enter the First Number  = ");
    cin>>a;

    cout<<("Enter the Second Number = ");
    cin>>b;

    cout<<("Arithmetic Operations on Integer Values\n");

    cout<<"Addition       = "<<addition(a, b); 
    cout<<"subtraction    = "<< subtraction(a, b);
    cout<<"multiplication = "<< multiplication(a, b);
    cout<<"division       = "<<division(a, b);
    cout<<"modulus        = "<< mod(a, b);
}

Output:

Enter the First Number  = 23
Enter the Second Number = 12
Arithmetic Operations on Integer Values
Addition       = 35
subtraction    = 11
multiplication = 276
division       = 1
modulus        = 11

Note: also read about Program to check Palindrome string

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Recent Posts

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

1 day ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

2 weeks ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

2 weeks ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

1 month ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

1 month ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

1 month ago