Advertisement
Filkolev

CalcPower Without Loops

Apr 8th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. public class PowersChallengeNoLoops
  5. {
  6.     public static void Main()
  7.     {
  8.         int number = int.Parse(Console.ReadLine());
  9.         int power = int.Parse(Console.ReadLine());
  10.  
  11.         BigInteger result = CalculatePower(1, number, power);
  12.  
  13.         Console.WriteLine(result);
  14.     }
  15.  
  16.     private static BigInteger CalculatePower(BigInteger result, int number, int power)
  17.     {
  18.         if (power == 0)
  19.         {
  20.             return result;
  21.         }
  22.  
  23.         power--;
  24.         result *= number;
  25.  
  26.         return CalculatePower(result, number, power);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement