Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi,
Please provide me the code for a^b programm in c# (both when b is +ve and -ve)
Posted
Updated 24-Nov-10 23:21pm
v2
Comments
Fredrik Bornander 25-Nov-10 5:21am    
Added tag.
Ankur\m/ 25-Nov-10 5:23am    
You are in a wrong place. People do not provide code here but help anyone who has tried hard and is stuck in some problem. Put some effort. I have given you a start.
CPallini 25-Nov-10 6:29am    
System.Math class provides the method Pow for the purpose, see: http://msdn.microsoft.com/en-us/library/system.math.pow.aspx

Start here: System.Math Class[^]
 
Share this answer
 
Comments
Member 13666878 7-Feb-18 19:44pm    
fun bin(n:int)=
let fun conv(ls)=
if ls=0 then []
else (ls mod 2) :: conv(ls div 2)
in
rev(conv(n))
end;
Just pass a and b to this function. This function will return the answer,

intAns = fnResult(2,3)
Function fnResult(Byval a as integer, Byval b as integer) as integer
Dim intAns as integer = 1

For i as integer=0 to b-1
  intAns = intAns * a
Next

return intAns 
End Function
 
Share this answer
 
v2
Comments
Ankur\m/ 25-Nov-10 5:54am    
Firstly, that's a VB code and the question is tagged C#. Secondly, this can be easily achieved using inbuilt function available in System.Math class. And finally I request you to not give direct answers to these questions. How do you think they will learn and how long will you help them write their code. Let them try, make mistakes and learn. I hope you understand what I mean.
Toniyo Jackson 25-Nov-10 5:59am    
ok. Thanks. What u have mentioned is correct. so i will not do it again.
CPallini 25-Nov-10 6:27am    
Uhm, Let's try your function with (2,-3) as input values.
:-)
Ankur\m/ 25-Nov-10 23:39pm    
I don't know why I have been voted down. But I do know that I didn't vote you.
Member 13666878 7-Feb-18 19:45pm    
fun bin(n:int)=
let fun conv(ls)=
if ls=0 then []
else (ls mod 2) :: conv(ls div 2)
in
rev(conv(n))
end;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900