Sunday, June 14, 2020

sum of closest float values in c

Three floating point values are passed as the input to the program. The program must print the sum of two numbers which are closest to each other with the precision up to 2 decimal places.

Example Input/Output 1:
Input:
2.45 6.78 2.35

Output:
4.80

solution:

int main()

{

float a,b,c;

scanf("%f %f %f",&a,&b,&c);

if(abs(a-b)<abs(b-c) && abs(a-b)<abs(a-c)){

    printf("%.2f",a+b);

}

else if(abs(b-c)<abs(a-b) && abs(b-c)<abs(a-c)){

    printf("%.2f",b+c);

}

else{

    printf("%.2f",a+c);

}


}

2 comments:

MFIB Comma Separated Integers

Fill in the blanks with code so that the program must accept three integers separated by a space and print them separated by a comma as the ...