We've been dealing with integers too much, it's time for float to shine!
Instructions:
Input five float numbers.
Print out the float numbers in one line, separated by spaces, and make sure you only print up to 1 decimal place.
Add the first four float numbers and check if their sum is greater than the fifth float number. Print out "Yes" if they are.
Input
1. First float number
2. Second float number
3. Third float number
4. Fourth float number
5. Fifth float number
Output
The first five lines will contain message prompts to input the five float numbers.
The next line contains the inputted float numbers.
The last line contains "Yes" if the condition is true.
Enter·the·first·number:·1.1
Enter·the·second·number:·1.2
Enter·the·third·number:·1.3
Enter·the·fourth·number:·1.4
Enter·the·fifth·number:·1.1
1.1·1.2·1.3·1.4·1.1
Yes
#include <stdio.h>
int main(){
float number1,number2,number3,number4,number5,sum;
printf("Enter the first number: ");
scanf("%f",&number1);
printf("Enter the second number: ");
scanf("%f",&number2);
printf("Enter the third number: ");
scanf("%f",&number3);
printf("Enter the fourth number: ");
scanf("%f",&number4);
printf("Enter the fifth number: ");
scanf("%f",&number5);
sum=number1+number2+number3+number4;
printf("%.1f %.1f %.1f %.1f %.1f\n",number1,number2,number3,number4,number5);
if(sum>number5){
printf("Yes\n");
}else{
printf("No\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment