Advertisement
Vladimir76

MathPower recursion

Jan 23rd, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 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. namespace Math_Power
  8. {
  9.     class Program
  10.     {
  11.         static double CalculatePower(double numValue, int powValue)
  12.         {
  13.             if (powValue==1)
  14.             {
  15.                 return numValue;
  16.             }
  17.             else
  18.             {
  19.                 return numValue*CalculatePower(numValue, powValue - 1);
  20.             }
  21.         }
  22.  
  23.         static void Main()
  24.         {
  25.             double number = double.Parse(Console.ReadLine());
  26.             int power = int.Parse(Console.ReadLine());
  27.  
  28.             double result = CalculatePower(number, power);
  29.             Console.WriteLine(result);
  30.            
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement