math.pow in C# using loop
static float CalculatePower(float x, int y)
{
float temp;
if (y == 0)
return 1;
temp = CalculatePower(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
{
if (y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}static void Main(string[] args)
{
float x = float.Parse(Console.ReadLine());
int y = int.Parse(Console.ReadLine());
float result = CalculatePower(x, y);
Console.WriteLine("{0} to the power of{1} is {2} ", x, y, result);
}
Also in C#:
- devexpress objectspace to session
- c# how to delete a file
- unity t-flip flop
- c# string array
- if and c#
- list.addrange in c#
- csharp first element of array
- c# remove specific character from string
- c# loop through repeater items
- c# shorten an definition
- convert array object to int[] c#
- take screenshot in c#
- unity custom editor save changes
- c# timespan
- c sharp exit while loop
- c# static review
- lazy loading c#
- transform.translate unity
- mvc write to console
- C# string is all zeros
- make an object disappear from a c# script unity
- c# change label forecolor code
- making pong in unity
- c# MD5.Create returning nul