C# program to calculate the 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#?
Submitted by Nidhi, on October 03, 2020

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.

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.