Advertisement
enevlogiev

recursive power func

Apr 9th, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class XtoY
  9. {
  10.     static void Main()
  11.     {
  12.         int result = Power(10, 6);
  13.         Console.WriteLine(result);
  14.     }
  15.  
  16.     static int Power(int x, int y)
  17.     {
  18.         if (y == 0)
  19.         {
  20.             return 1;
  21.         }
  22.         if (y == 1)
  23.         {
  24.             return x;
  25.         }      
  26.         return x * Power(x, y - 1);      
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement