Advertisement
Filkolev

CalcPower Without Multiplication

Apr 8th, 2015
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. public class PowersChallenge
  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 = number;
  12.  
  13.         for (int i = 0; i < power - 1; i++)
  14.         {
  15.             result = Multiply(result, number);
  16.         }
  17.  
  18.         Console.WriteLine(result);
  19.     }
  20.  
  21.     private static BigInteger Multiply(BigInteger a, int b)
  22.     {
  23.         BigInteger result = 0;
  24.  
  25.         for (int i = 0; i < b; i++)
  26.         {
  27.             result += a;
  28.         }
  29.  
  30.         return result;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement