Answer to Question #280063 in C for Secret

Question #280063

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.


1
Expert's answer
2021-12-15T11:37:43-0500
#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;
}

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