2. SHORT QUESTIONS: Declare a named constant PLUS which has a value a) b) Write
ID: 3592075 • Letter: 2
Question
2. SHORT QUESTIONS: Declare a named constant PLUS which has a value a) b) Write a selection statement to express the following: Given an integer n, test if it is negative then display n is a negative number. e) Declare a function FX that takes two integers A and B and returns the average o the two d) Given a void function declaration as below: void Sum(double a, double b, double& c); value of c is stored in a variable called result e) Give the title of a value return function which takes two input variables: x a ction from main with passing the value of a as 2.5 and b as 6.7 and the loating point variable and y a character variable, and the output is a Boolean type. 3.Predict output from each of the following C++ statements a) Given double y y=712, coutExplanation / Answer
#include<stdio.h>
const char PLUS = '+'; // 2(a)
double FX(int A,int B) // 2(c)
{
return (A+B)/2.0;
}
void Sum(double a,double b,double& c) // 2(d)
{
c=a+b;
}
int main()
{
int n;
printf("Enter the value of n : ");
scanf("%d",&n);
if(n<0)
printf(" n is a negative number"); // 2(b)
int A,B;
double avg=0.0;
printf(" Enter the value of A : ");
scanf("%d",&A);
printf(" Enter the value of B : ");
scanf("%d",&B);
avg=FX(A,B);
printf(" Average of A and B is %f",avg);
double a,b;
double c=0.0;
printf(" Enter the value of a : ");
scanf("%lf",&a);
printf(" Enter the value of b : ");
scanf("%lf",&b);
Sum(a,b,c);
printf(" Sum of a and b is c = %lf",c);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.