Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to perform Division of Exponents of Same Base using C#?
When dividing exponents with the same base, we use the mathematical rule: a^m ÷ a^n = a^(m-n). This means we subtract the exponent in the denominator from the exponent in the numerator while keeping the base unchanged.
In C#, we can implement this rule by subtracting the exponents and then using Math.Pow() to calculate the final result.
Mathematical Rule
The division rule for exponents with the same base is −
a^m ÷ a^n = a^(m-n)
For example: 10^10 ÷ 10^8 = 10^(10-8) = 10^2 = 100
Using Math.Pow() Method
Example
using System;
class Demo {
static void Main() {
double res, n, e1, e2;
n = 10;
e1 = 10;
e2 = 8;
res = e1 - e2;
Console.WriteLine("Result = {0}^{1} : {2}", n, res, Math.Pow(n, res));
}
}
The output of the above code is −
Result = 10^2 : 100
Using Different Base and Exponents
Example
using System;
class ExponentDivision {
static void Main() {
double baseValue = 5;
double exponent1 = 7;
double exponent2 = 3;
double resultExponent = exponent1 - exponent2;
double finalResult = Math.Pow(baseValue, resultExponent);
Console.WriteLine("{0}^{1} ÷ {0}^{2} = {0}^{3}", baseValue, exponent1, exponent2, resultExponent);
Console.WriteLine("Final Result: {0}", finalResult);
}
}
The output of the above code is −
5^7 ÷ 5^3 = 5^4 Final Result: 625
Creating a Reusable Method
Example
using System;
class ExponentCalculator {
static double DivideExponents(double baseValue, double exp1, double exp2) {
double resultExponent = exp1 - exp2;
return Math.Pow(baseValue, resultExponent);
}
static void Main() {
double result1 = DivideExponents(2, 8, 3);
double result2 = DivideExponents(3, 6, 2);
double result3 = DivideExponents(10, 5, 2);
Console.WriteLine("2^8 ÷ 2^3 = 2^5 = {0}", result1);
Console.WriteLine("3^6 ÷ 3^2 = 3^4 = {0}", result2);
Console.WriteLine("10^5 ÷ 10^2 = 10^3 = {0}", result3);
}
}
The output of the above code is −
2^8 ÷ 2^3 = 2^5 = 32 3^6 ÷ 3^2 = 3^4 = 81 10^5 ÷ 10^2 = 10^3 = 1000
Conclusion
Division of exponents with the same base follows the simple rule of subtracting the exponents: a^m ÷ a^n = a^(m-n). In C#, implement this by subtracting the exponents and using Math.Pow() to calculate the final result.
