For example I am trying to calculate 9704−36 in C#. How should i go about doing this? I am using Visual C# 2010 Express
Asked
Active
Viewed 5,377 times
0
-
1How about `Math.Pow(9704,-36)` ? – V4Vendetta Sep 20 '11 at 09:46
-
2[First thing to do](http://www.google.co.in/search?gcx=w&sourceid=chrome&ie=UTF-8&q=c%23+exponent) – NaveenBhat Sep 20 '11 at 09:46
-
1@Nook Don't change the question. If you asked the wrong question that's your problem not ours. Now we are getting downvotes and look like idiots. If you want to ask the right question then ask it as a new question. – David Heffernan Sep 20 '11 at 10:23
-
@nook thank you for heeding my advice and asking a [new question for your modular arithmetic question](http://stackoverflow.com/questions/7483706/c-modinverse-function). – David Heffernan Sep 20 '11 at 10:38
-
@Justin OP mentioned `exponent` in the title. – NaveenBhat Sep 20 '11 at 10:39
-
@Knvn Ah - The edit I saw didn't mention exponents - its been changed since then. – Justin Sep 20 '11 at 10:42
2 Answers
5
Use Math.Pow(9704, -36)
. C# does not have a dedicated exponentiation operator and Math.Pow
fills the gap.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490
-
It seems that you don't know what is http://en.wikipedia.org/wiki/Modular_multiplicative_inverse – Maxim Razin Sep 20 '11 at 10:21
-
@grep It seems that you didn't notice that the question changed. Original question about negative exponents has been restored. – David Heffernan Sep 20 '11 at 10:21
-
@grep you should post your deleted answer at the [new question](http://stackoverflow.com/questions/7483706/c-modinverse-function) – David Heffernan Sep 20 '11 at 10:37
1
Exactly the same way you do it for a positive exponent:
Math.Pow(9704,-36)
There is no power operator in C# (^
is exclusive or, not power), so you need to use the Math.Pow function.

CodesInChaos
- 106,488
- 23
- 218
- 262