Arithmetic operators using function in C++


This code defines five functions sum(), diff(), pro(), divi(), and mod() to perform arithmetic operations on two integers. The sum() function returns the sum of two integers, the diff() function returns the difference between two integers, the pro() function returns the product of two integers, the divi() function returns the integer division of two integers, and the mod() function returns the remainder after division of two integers. The main function calls all these functions and displays the results of the arithmetic operations.

Source Code

#include<iostream>
using namespace std;
int sum(int num1, int num2)
{
    int num3=num1+num2;
    return num3;
}
int diff(int num1, int num2)
{
    int num3=num1-num2;
    return num3;
}
int pro(int num1, int num2)
{
    int num3=num2*num1;
    return num3;
}
int divi(int num1, int num2)
{
    int num3=num2/num1;
    return num3;
}
int mod(int num1, int num2)
{
    int num3=num2%num1;
    return num3;
}
int main()
{
    cout<<"\nAddition :"<<sum(10,2);
    cout<<"\nSubtraction :"<<diff(10,2);
    cout<<"\nMultiplication :"<<pro(10,2);
    cout<<"\nDivision :"<<divi(10,2);
    cout<<"\nModulo division :"<<mod(10,2);
    return 0;
}
To download raw file Click Here

Output

Addition :12
Subtraction :8
Multiplication :20
Division :0
Modulo division :2

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples