C# - Multiplication of Two Exponents of the Same Base

Here, we are going to learn how to calculate the multiplication of two exponents of the same base in C#? By Nidhi Last updated : April 15, 2023

Here, we will calculate the multiplication of two exponents of the same base, here we will read the values of the base and exponents then find the sum of exponents and then calculate multiplication using Pow() method of Math class.

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

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.

C# Basic Programs »


Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.