Skip to content

Instantly share code, notes, and snippets.

@Plus1XP
Last active March 12, 2018 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Plus1XP/ce171034576669f7dfc0b709bcd81381 to your computer and use it in GitHub Desktop.
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.
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