Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- partial class Program
- {
- public static double Power(double n, int k) {
- if (k == 0) {
- return 1;
- }
- if (k % 2 == 0) {
- var p = Power(n, k / 2);
- return p * p;
- }
- else {
- return n * Power(n, k - 1);
- }
- }
- public static void Main(string[] args)
- {
- string f = Console.ReadLine();
- string s = Console.ReadLine();
- double n;
- int k;
- if (!double.TryParse(f, out n) || !int.TryParse(s, out k) || k < 0)
- Console.WriteLine("Incorrect input");
- else
- Console.WriteLine(Power(n, k));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment