Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate power-of in C#?

Tags:

c#

math

I'm not that great with maths and C# doesn't seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:

var dimensions = ((100*100) / (100.00^3.00)); 
like image 400
davethecoder Avatar asked Sep 02 '09 09:09

davethecoder


People also ask

How do you find the power of 2 in C?

Another solution is to keep dividing the number by two, i.e, do n = n/2 iteratively. In any iteration, if n%2 becomes non-zero and n is not 1 then n is not a power of 2. If n becomes 1 then it is a power of 2.

What is power of a number in C?

In other words, a pow() function is used to calculate the power of the base number (x) by raising the power of (y) as (xy). For example, we take base as 2 and power as 5, the power of a number using the pow(2, 5) function to return a value as the 32.


2 Answers

See Math.Pow. The function takes a value and raises it to a specified power:

Math.Pow(100.00, 3.00); // 100.00 ^ 3.00 
like image 82
Paul Turner Avatar answered Sep 24 '22 10:09

Paul Turner


You are looking for the static method Math.Pow().

like image 24
Daniel Brückner Avatar answered Sep 23 '22 10:09

Daniel Brückner