Teacher gave a question today to find Base is 2 and power is 3. so that Answer should be 8. so to find that she told us to use Recursion and do it. i done it in the normal way. but when i do it in the Recursion way. one error coming saying too Few Parameters

please check


int multi(int,int);

int x=0,y=0;

printf("Enter Your Base Number:");

printf("Enter the Power Number:");

printf("The power of %d is %d",x,multi(x,y));


int multi (int x, int y)
int ans=0;

	 return 1;

	 return ans;


Recommended Answers

All 7 Replies

here's your problem:

return 1;

it should be:

		return x;
		return 1;


thanks my bad. in my coding i have put if(y<=1) it should be ( y<1) only . no equal sign.

thanks guys. thanks for the quick reply

yeah, i guess mine was redundant. i still dont think well in recursion.

The program you have written using recursion is logically wrong..

You have written the code if (y<=1) return=1
How can 2 power -1 will be equal to one..

So correct your program first and then see the results..

because he doesnt have to handle negative powers for his CS 101 class.


i agree. i thought about including that in my original answer, but decided to stick to the question as presented. some of the posters here (not necessarily this one) sort of implode if you throw too much at them.

anyhow... yeah, change your answer variable to type "double" , use the absolute value of the power to calculate the answer, and then throw this in at the end: if (pow<0) ans = 1.0/ans; pretty simple, really.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.