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);
}
}
Guys use fabs() instead of abs()
ReplyDeleteLogic???
ReplyDelete