Product Learn programming C# Sharp

Lesson:

Flow Control


Exercise:

Product 13


Objetive:

Create a C# program which asks the user for two integer numbers and displays their multiplication, but not using "*". You must use consecutive sums. (Hint: remember that 3*5 = 3+3+3+3+3 = 15)


Code:

using System;
public class exercis40
{
    public static void Main()
    {
        Console.Write("Enter the first number: ");
        int n1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter the second number: ");
        int n2 = Convert.ToInt32(Console.ReadLine());

        int result = 0;
        int i = 0;

        while (i < n2)
        {
            result = result + n1;
            i++;
        }
        Console.WriteLine("{0} X {1} = {2}", n1, n2, result);
    }
}