Write a C++ program to do the following: 1. Define a function called \"differenc
ID: 3687862 • Letter: W
Question
Write a C++ program to do the following:
1. Define a function called "difference" that can accept two integer values as arguments and returns an integer (which is the obtained by subtracting the first the second argument from the first argument.
2. Declare two variables in the main function and assign them values 7 and 10.
3. Call the difference function with the above created variables as arguments. Print the returned difference in the main function.
4. Call the function again with 11 and 5 as arguments and print the obtained difference.
Explanation / Answer
# include <iostream>
using namespace std;
int difference ( int a , int b ) // STEP 1
{
int r;
r = a-b;
return r;
}
int main()
{
int x = 7 , y = 10 , z ; //STEP 2
z = difference(x , y); //STEP 3
cout << "The result is " <<difference(x , y) << ' ' ;
z = difference(11 , 5); // STEP 4
cout << " The result is " <<difference(11 , 5) << ' ' ;
}
Output :
The result is -3
The result is 6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.