1) Write a program to accept 4 integers as parameters to a function.
Do the following:
a) Find the sum and average of the four numbers. Print the sum and average of the four numbers.
b) Find the sum of the first two numbers and the last two numbers separately. Print the sums separately.
c) Using if else, find out whether the sum of the first two numbers is greater than the sum of the last two
numbers.
d) Write an output. If the numbers are: 5,10,15,20, then the output should be similar to:
Sum of the four numbers: 50
Average of the four numbers: 12.5
Sum of the first two numbers: 15
Sum of the last two numbers: 35
Sum of first two greater than last two: false
Answers
Note: I am using C++ programming language.
#include<iostream>
using namespace std;
int Calculation(int a,int b ,int c, int d) {
float sumOfNumbers = a+b+c+d ;
float avg = sumOfNumbers /4 ;
cout<<"\nSum of four numbers : " <<sumOfNumbers <<endl;
cout<<"\nAverage of four numbers : "<<avg <<endl;
cout<<"\nSum of first two numbers : " <<a+b <<endl ;
cout<<"\nSum of last two numbers : " <<c+d <<endl ;
if((a+b) > (c+d)) cout<<"\nSum of first two greater than last two : TRUE " <<endl;
else cout<<"\nSum of first two greater than last two : FALSE "<<endl;
}
int main () {
int num1,num2,num3,num4;
cout<<"Enter numbers of four numbers :\n" ;
cin>>num1>>num2>>num3>>num4 ;
Calculation(num1,num2,num3,num4) ;
return 0;
}
** Please mark this ans as Brainliest answer. Thank you!