Last active
March 12, 2018 11:27
-
-
Save Plus1XP/ce171034576669f7dfc0b709bcd81381 to your computer and use it in GitHub Desktop.
Method to calculate the power of an int without using the Math.Pow Method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private long CalculatePower(int Number, int PowerOf) | |
{ | |
long Result = Number; | |
for (int i = PowerOf; i > 1; i--) | |
{ | |
Result = (Result * Number); | |
} | |
return Result; | |
} | |
CalculatePower(5, 3); // 125 | |
CalculatePower(8, 4); // 4096 | |
CalculatePower(6, 2); // 36 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment