Sunday, September 29, 2013

P2C2: C Sharp Program - Multiplication of two numbers using function

//Multiplication of two numbers using function
using System;

public class MultiplicationProgram
{
   static long Multiply (int n1, int n2)
    {
        return (n1 * n2);
    }

    public static void Main()
    {
        int num1, num2;
        long mul=1;

        Console.WriteLine("Enter First Number:");
        num1=Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Enter Second Number:");
        num2 = Convert.ToInt32(Console.ReadLine());

        mul = Multiply(num1, num2);
     
        Console.WriteLine("\nMultiplication = {0} * {1} = {2}",num1, num2, mul);
        Console.WriteLine("\nPress any key to exit...");
        Console.ReadLine();

    }
}

OUTPUT:

Enter First Number:
10
Enter Second Number:
20

Multiplication = 10 * 20 = 200

Press any key to exit...

No comments:

Post a Comment