by CodeChum Admin
Whole numbers are great, but I think we should also pay attention to decimal numbers, too.
So, how about we make a program that involves a lot of decimals?
Instructions:
Input
1. A series of float numbers
Output
The first multiple lines containing message prompts for float numbers.
The last line contains the sum with 2 decimal places.
Enter a number: 1.1
Enter a number: 1.2
Enter a number: 1.3
Enter a number: 1.4
Enter a number: -1.0
Sum = 4.00
#include <stdio.h>
int main()
{
float number;
float sum=0;
do{
printf("Enter a number: ");
scanf("%f",&number);
sum+=number;
}while(sum<100 && number>0);
printf("Sum = %.2f\n",sum);
scanf("%f",&sum);
return 0;
}
Comments
Leave a comment