Add and Subtract using a return function in c++

WAP to add and subtract 2 numbers using function and display result from main in c++

Add and Subtract using a function in c++

// 3.WAP to add and subtract 2 numbers using function and display result from main.

#include<iostream>
using namespace std;

int add(int, int);
int sub(int, int);

int main() {
	int a, b, adds, subs;
	cout<<"Enter two numbers: \n";
	cin>>a>>b;
	adds = add(a,b);
	subs = sub(a,b);
	cout<<"\nSum: "<<adds;
	cout<<"\nSub: "<<subs;
	return 0;
}

int add(int a, int b) {
	return a + b;
}

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

Output

Enter two numbers:
5
2
Sum: 7
Sub: 3

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments