Introduction
In this blog, we are going to see the calculation power of Exponent Method in C# programming language.
We're going to use that the same basic console programs.
What is the Exponent Method?
An exponent refers to the number of times a number is multiplied by itself.
For example, 2 to the 3rd means: 2 x 2 x 2 = 8. 2 to the power 3 is not the same as 2 x 3 = 6. Remember that a number raised to the power of 1 is itself.
Let's start!
- These programs have all been successfully executed in Visual Studio.
- The following each program has two outputs.
Calculate Power Exponent value
- using System;
- class Expo {
- static void Main() {
- double m, n;
- Console.WriteLine("Enter the Number : ");
- m = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the Exponent : ");
- n = double.Parse(Console.ReadLine());
- double value1 = Math.Pow(m, n);
- Console.WriteLine("Result : {0}", value1);
- Console.ReadLine();
- }
- }
Addition of Exponent of the same base
- using System;
- class ExpoAdd {
- static void Main() {
- Console.WriteLine("Enter the Base Value : ");
- double num = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the First Exponent :");
- double exp1 = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the Second Exponent :");
- double exp2 = double.Parse(Console.ReadLine());
- double add;
- add = exp1 + exp2;
- Console.WriteLine("Result is : {0}^{1} : {2}", num, add, Math.Pow(num, add));
- Console.ReadLine();
- }
- }
Subtraction of Exponent of the same base
- using System;
- class ExpoSub {
- static void Main() {
- Console.WriteLine("Enter the Base Value : ");
- double num = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the First Exponent :");
- double exp1 = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the Second Exponent :");
- double exp2 = double.Parse(Console.ReadLine());
- double sub;
- sub = exp1 - exp2;
- Console.WriteLine("Result is : {0}^{1} : {2}", num, sub, Math.Pow(num, sub));
- Console.ReadLine();
- }
- }
Multiplication of Exponent of the same base
- using System;
- class ExpoMulti {
- static void Main() {
- Console.WriteLine("Enter the Base Value : ");
- double num = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the First Exponent :");
- double exp1 = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the Second Exponent :");
- double exp2 = double.Parse(Console.ReadLine());
- double mul;
- mul = exp1 * exp2;
- Console.WriteLine("Result is : {0}^{1} : {2}", num, mul, Math.Pow(num, mul));
- Console.ReadLine();
- }
- }
Division of Exponent of the same base
- using System;
- class ExpoDivi {
- static void Main() {
- Console.WriteLine("Enter the Base Value : ");
- double num = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the First Exponent :");
- double exp1 = double.Parse(Console.ReadLine());
- Console.WriteLine("Give the Second Exponent :");
- double exp2 = double.Parse(Console.ReadLine());
- double div;
- div = exp1 / exp2;
- Console.WriteLine("Result is : {0}^{1} : {2}", num, div, Math.Pow(num, div));
- Console.ReadLine();
- }
- }
Thanks for reading... Cheers!