Finding power of a number (If the number is 5 and the power is 10, then it displays 5 power 0 till 5 power 10)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Power
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter
the number : ");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter
the power : ");
int power = Convert.ToInt32(Console.ReadLine());
int counter;
int result;
for(int i = 0; i <= power; i++)
{
result = 1;
counter = i;
while(counter > 0)
{
result = result * number;
counter--;
}
Console.WriteLine(number + " to the " + i + "
power is " + result);
}
Console.ReadLine();
}
}
}
Output :
No comments:
Post a Comment