Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program C HELP. - In the program I need to make a input three real (floating poi

ID: 3787477 • Letter: P

Question

program C HELP.

- In the program I need to make a input three real (floating point) numbers from the keyboard and calculate a number of properties about the numbers.

-3 values would read a single scanf() statement.

-Then call each of five functions you will write.

-Each function will pass the three values that are input the function will perform the requested calculation. then return the required result.

- functions to be written are----

- Determine which of 3 #'s is largest and return that value.

-Determine which of 3#'s values is the smallest and return that value.

-Determine if all 3 #'s are equal to each other.

Return the character ‘=’ if they are, or the character ‘#’ if two or more have different values.

Calculate and return the average of the 3 values

An example is attached when run.

This program will calculate several properties with respect to three floating point values entered. Enter three real numbers 6.05 6.1 7.5 val 1 val 2 val 3 Max Min Avg All-Equal Near-Equal Epsilon I I 6.05 6.10 7.50 7.50 6.05 6.55 No Yes

Explanation / Answer


// C code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define EPSILON 0.1
// - Determine which of 3 #'s is largest and return that value.
float maxval (float v1 , float v2 , float v3)
{
if(v1 > v2 && v1 > v3)
return v1;
else if(v2 > v1 && v2 > v3)
return v2;
else
return v3;
}

// -Determine which of 3#'s values is the smallest and return that value.
float minval (float v1 , float v2 , float v3)
{
if(v1 < v2 && v1 < v3)
return v1;
else if(v2 < v1 && v2 < v3)
return v2;
else
return v3;
}

// -Determine if all 3 #'s are equal to each other.
// Return the character ‘=’ if they are, or the character ‘#’ if two or more have different values.
char equalval (float v1 , float v2 , float v3)
{
if(v1 == v2 && v2 == v3 && v1 == v3)
return '=';
else
return '#';
}

// Calculate and return the average of the 3 values
float averageval (float v1 , float v2 , float v3)
{
return (v1+v2+v3)/3;
}
// Check if the first two numbers entered are “nearly” equal, i.e. if value 1 and value 2 differ by less than some tolerance called EPSILON (define this globally with a #define statement). If they are nearly equal, return the character ‘Y’ (for yes) and if not, return the character ‘N’ (for NO).
char nearequal(float v1 , float v2)
{
if(abs(v2-v1) < EPSILON)
return 'Y';
else
return 'N';
}

int main()
{
float v1 ,v2, v3;
printf("Enter three real numbers: ");
scanf("%f%f%f",&v1,&v2,&v3);

float max = maxval(v1,v2,v3);
float min = minval(v1,v2,v3);
float avg = averageval(v1,v2,v3);
char eql = equalval(v1,v2,v3);
char equal[10];
if(eql == '=')
strcpy(equal, "Yes");
else
strcpy(equal, "No");
char neql = nearequal(v1,v2);
char nequal[10];
if(neql == 'Y')
strcpy(nequal, "Yes");
else
strcpy(nequal, "No");

printf("---------------------------------------------------------------------------------------------------------------------------------------------------------- ");
printf("Val1 Val2 Val3 Max Min Avg All-Equal Near-Equal EPSILON ");
printf("---------------------------------------------------------------------------------------------------------------------------------------------------------- ");
printf("%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f %s %s %0.2f ",v1,v2,v3,max,min,avg,equal,nequal,EPSILON);
printf("---------------------------------------------------------------------------------------------------------------------------------------------------------- ");

return 0;
}

/*
outpput:

Enter three real numbers: 6.05 6.10 7.50
----------------------------------------------------------------------------------------------------------------------------------------------------------
Val1 Val2 Val3 Max Min Avg All-Equal Near-Equal EPSILON
----------------------------------------------------------------------------------------------------------------------------------------------------------
6.05 6.10 7.50 7.50 6.05 6.55 No Yes 0.10
----------------------------------------------------------------------------------------------------------------------------------------------------------

*/