Answer to Question #267129 in C for jme

Question #267129

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.


1
Expert's answer
2021-11-16T18:35:46-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS