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.
#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;
}
Comments
Leave a comment