In thi tutorial, we will find the product of a sequence of numbers.
Variables are defined in the first row. In the next lines, values are assigned to these variables.
In the last line we print the result of processing on the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class Program { static void Main(string[] args) { int num1; int num2; long result=1; //important must result=1 Console.Write("\n \n *** www.csharp-console-examples.com \n \n"); Console.Write(" --- C# Program to find product of Two Integers --- \n \n"); Console.Write("Enter first number(low):"); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Second number(high):"); num2 = Convert.ToInt32(Console.ReadLine()); for (int i = num1; i < num2; i++) { result *= num1; } Console.Write("The product of two numbers is:" + result); Console.ReadLine(); } } |
Output:
You can find more similar examples of programming for this programming language in the site.