Make a loop that will accept random decimal/float numbers. When the user inputs 0, the loop will terminate and then output the sum of all negative numbers inputted in 3 decimal places.
#include <stdio.h>
int main() {
sum_negative = 0;
while ( 1 ) {
int n;
printf("%f", &n);
if (n < 0.0)
sum_negative += n;
else if (n==0)
break;
}
printf("%.3f", sum_negative);
return 0;
}
Comments
Leave a comment