Well in line 30...I am a little confused on why you are actually calling the function that you are already in again..Enlighten me please, as im in my first semester of my ass. in CS.
and also to find a negative power, dont you turn the number into a fraction.. so if it was 20-2 it would be 1/202
and my way worked..I dont know why i cannot grasp ur concept. I tested yours out and it works for the normal raising to the powers but the negative ones dont work...doing it with for loops i just changed the exponent to a positive by multiplying it by -1 and then changing the base by dividing it on 1.
The program is correct for the most part. The only major correction I see that needs to be made is that on line 34, the second parameter to the raising() call should be -y-1, not y-1. Otherwise you'll cause infinite recursion.
Also, the parameters for raising() should be int, not double. The code doesn't behave well with fractional values.
There are other minor problems, but the program should behave correctly even with them.
hi, line 30 is actually to output the power result. if I remove it the return value will be always 1.
Nope. Lines 30 and 35 never execute because return gives the control flow back to the caller. Those lines do nothing at all; the compiler may even be ignoring them.
I really dont understand how this is raising to a power, it doesnt use the funtion pow and it doesnt use loops..so how does this raise to the power?
return x * (rasing(x, y-1));
Does it have something to do with the y-1 part?, I dont understand why you need to put two permiters in there again... Can anybody explain the logic to me.
CuLLen look, this program is an example of a recursion. (You may google it) You would probably handle it the next sem. The main point of it is that the function calls itself but reduces Y on one, until it reaches 0.
like for example base is 4 exp is 3 it multiplies 4 on 3 three times: 4 *3 = 12 than 12 * 3 etc...