CSharp - Write program to Calculate the Product of the Entered Numbers

Requirements

The user enters numbers with the last one being 0.

The program you created displays the product of all the entered numbers with the exclusion of the final 0.

Hint

The product variable starts at a value of 1 contrary to 0, which you used when calculating the sum.

When updating the product, you need to take care not to include the final 0.

You declare the product variable in type double for the result not to overflow.

Demo

using System;
class Program// w  w  w .  ja v a 2s  . c o  m
{
    static void Main(string[] args)
    {
        // Preparations 
        double product = 1;
        int number;
        // Entering numbers until zero 
        do
        {
            // Input 
            Console.Write("Enter a number (0 = end): ");
            string input = Console.ReadLine();
            number = Convert.ToInt32(input);

            // Accumulating in intermediate product (but not the last zero!) 
            if (number != 0)
            {
                product *= number;
            }

        } while (number != 0);
        // Output 
        Console.WriteLine("Product of entered numbers (excluding zero) is: " +product.ToString("N0"));
    }
}

Result