Instructions
Input four decimal numbers, they could be positive or negative.
Add all the negative numbers, and print the sum, up to 2 decimal places.
Input
A line containing four decimals/floats separated by a space.
#include <stdio.h>
int main() {
double x;
double sum = 0;
for (int i=0; i<4; i++) {
scanf("%lf", &x);
if (x < 0) {
sum += x;
}
}
printf("%.2lf\n", sum);
return 0;
}
Comments
Leave a comment