Question 1
Write functions that do the following:
i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters.
ii) A function that takes 2 arguments and returns the difference,
iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Question 2
Write functions:
i) One that prompts a user for 2 numbers.
ii) Adds the two numbers if they are even
iii) Multiplies the two numbers if they are odd
iv) Displays the appropriate output to the user
You are writing 4 functions and calling them to test functionality.
1)
Code:
#include <iostream>
using namespace std;
int add(int a , int b)
{
return a+b;
}
int diff(int a, int b)
{
if(a > b)
{
return a - b;
}
return b - a;
}
void prod()
{
int x = add(4, 5);
int y = diff(10, 1);
cout<< "Product : "<<x * y;
}
int main() {
prod();
return 0;
}
Screenshots:
Get Answers For Free
Most questions answered within 1 hours.