In: Computer Science
#include<iostream>
using namespace std;
void calcSumAndDiff(int ,int, int &, int &);
void calcSumAndDiff(int n1,int n2, int &sum, int &diff){
sum = n1 + n2;
diff = n1 - n2;
}
int main()
{
int n1,n2,sum,diff;
n1=30;n2=10;
calcSumAndDiff(n1,n2,sum,diff);
cout<<"Sum is
:"<<sum<<endl;
cout<<"Diff is:"<<diff<<endl;
system("pause");
}
If you have any doubts please comment below. Please give upvote if you like this.
C++ Code:
// If we include #include<bits/stdc++.h> we don't want to
include any header files
#include<iostream>
// system() is used to invoke an operating system command from a
C/C++ program
#include<stdlib.h>
using namespace std;
void calcSumAndDiff(int ,int, int &, int &); // It is no
need to declare because here we instalise
// here we instalise the function
void calcSumAndDiff(int n1,int n2, int &sum, int
&diff)
{
sum = n1 + n2;
diff = n1 - n2;
}
// Main function
int main()
{
int n1,n2,sum,diff;
// instalise the n1 and n2 values as 30 and 10
respectively
n1=30;n2=10;
// Calling method calcSumAndDiff with parameters
calcSumAndDiff(n1,n2,sum,diff);
// Display the sum value after calling the
function
cout<<"Sum is :"<<sum <<endl;
// Display the diff value after calling the
function
cout<<"Diff is:"<<diff <<endl;
//system(“pause”) which is used to execute pause
command and make the screen/terminal
//wait for a key press, and system(“cls”) which is
used to make the screen/terminal clear.
system("pause");
return 0;
}