Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.40 KB | None | 0 0
  1. namespace ConsoleApp13
  2. {
  3.     public static class PowerUtil
  4.     {
  5.         public static int Exp(int x, int no)
  6.         {
  7.             if (no == 1)
  8.             {
  9.                 return x;
  10.             }
  11.             var reminder = no % 2;
  12.             var value = Exp(x, no / 2);
  13.             return reminder == 0 ?
  14.                 (value * value) :
  15.                 (x * value * value);
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement