Signup/Sign In

C++ Program To Perform All Arithmetic Operations Using Functions

This tutorial will learn how to perform all arithmetic operations using functions.

Perform All Arithmetic Operations Using Functions In C++ Language

Here, we need to make separate functions for addition, subtraction, division, and multiplication for two variables input by the user.

Let's implement the concept in C++.

#include<iostream>
using namespace std;

int sum(int,int);
int sub(int,int);
int mul(int,int);
int div(int,int);
int rem;

int main()
{

 int a,b,m,su,s,d;

 cout<<"Enter Two Numbers : \n";
 cin>>a>>b;

 s=sum(a,b);
 su=sub(a,b);
 m=mul(a,b);
 d=div(a,b);

 cout<<"\nSum : = "<<s<<"\nSubtraction : = "<<su<<endl;
 cout<<"\nMultiplication : = "<<m<<"\n Division : = "<<d<<endl;
 return 0;
}

int sum(int a,int b)
{
 rem=a+b;
 return(rem);
}

int sub(int a,int b)
{
 rem=a-b;
return(rem);
}

int mul(int a,int b)
{
 rem=a*b;
return(rem);
}

int div(int a,int b)
{
 rem=a/b;
return(rem);
}


Enter Two Numbers :
15 2

Sum : = 17
Subtraction : = 13

Multiplication : = 30
Division : = 7

Conclusion

In this tutorial, mainly we have focused on how to build functions according to the given conditions or operations.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.