Author : Rahul

Write a program to calculate the power of a number


Program

using System;

namespace ProgrammingQuestion
{
 class Program
 {
   static void Main(string[] args)
   {
     //Variable Declaration
     string numberVal,powerVal;
     int number, power, result=1;
     
     //User Input
     Console.Write("Enter Number:");
     numberVal = Console.ReadLine();
     number = Convert.ToInt32(numberVal);
     Console.Write("Enter Power:");
     powerVal = Console.ReadLine();
     power = Convert.ToInt32(powerVal);

     //Power Logic
     for (int i=1;i<=power;i++)
     {
       result = result * number;
     }
     
     //Print Result
     Console.WriteLine($"Power {power} of the Number {number} : {result}");
     Console.Read();
   }
 }
}

Output

Enter Number:5
Enter Power:3
Power 3 of the Number 5 : 125