Assignments » User Defined Function » Set1 » Solution 1

Write a C++ program using function which accept two integers as an argument and return its sum. Call this function from main( ) and print the results in main( ).

    
#include<iostream>
using namespace std;

int sum(int, int);

int main()
{
	int x,y,s;
	cout<<"Enter first number : ";
	cin>>x;
	cout<<"Enter second number : ";
	cin>>y;
	s=sum(x,y);
	cout<<"The sum is : "<<s;

	
	return 0;
}

int sum(int a, int b)
{

	int total;
	total=a+b;
	return total;
}

Enter first number : 45
Enter second number : 56
The sum is : 101

 

 

«back