Q:

C# program to calculate the multiplication of two exponents of the same base

belongs to collection: C# Basic Programs | basics

0

C# program to calculate the multiplication of two exponents of the same base

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to calculate the multiplication of two exponents of the same base is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to calculate the multiplication 
//of two exponents of the same Base

using System;

class MathEx
{
    static void Main()
    {
        double Base                 = 0.0;
        double Exponent1            = 0.0;
        double Exponent2            = 0.0;
        double ExponentSum          = 0.0;
        double ExpMultiplication    = 0.0;
        

        Console.Write("Enter the value of base: ");
        Base = Convert.ToDouble(Console.ReadLine());
        
        Console.Write("Enter the value of 1st exponent:");
        Exponent1 = Convert.ToDouble(Console.ReadLine());

        Console.Write("Enter the value of 2nd exponent:");
        Exponent2 = Convert.ToDouble(Console.ReadLine());

        ExponentSum = Exponent1 + Exponent2;

        ExpMultiplication = Math.Pow(Base, ExponentSum);

        Console.WriteLine("{0}^{1} : {2}", Base, ExponentSum, ExpMultiplication);
    }
}

Output:

Enter the value of base: 2
Enter the value of 1st exponent:3
Enter the value of 2nd exponent:2
2^5 : 32
Press any key to continue . . .

Explanation:

Here, we created a class MathEx that contains the Main() method. The Main() method is used as an entry point for the program. Here we read the values of variables Base, Exponent1, and Exponent2. Then we calculated the sum of exponents. After that, we calculated the result using the Pow() method of Math class and print the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to print Floyd\'s triangle... >>
<< C# program to calculate the sum of two binary numb...