Answer to Question #297794 in C for Harsh

Question #297794

Input numbers from the user and find the product of all those input numbers until the user


inputs a negative number. In other means, the loop should end when the user enters a


negative number. Finally, display the product of all those positive numbers entered by the


user.

1
Expert's answer
2022-02-16T08:10:30-0500
#include <stdio.h>

int main()
{
    int product = 1;
    int number = 0;
    
    printf("Input numbers:\n");
    while (number >= 0)
    {
        scanf("%d", &number);        
        if (number >= 0)
        {
            product *=  number;
        }
    }
    printf("Product of all positive numbers = %d", product);  
    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