•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 391,705 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,257 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 436 | Replies: 7 | Solved
![]() |
•
•
Join Date: May 2008
Posts: 52
Reputation:
Rep Power: 0
Solved Threads: 4
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
PLEASE HELP ME IN THIS
please check
c Syntax (Toggle Plain Text)
#include<stdio.h> int multi(int,int); main() { int x=0,y=0; printf("Enter Your Base Number:"); scanf("%d",&x); printf("Enter the Power Number:"); scanf("%d",&y); printf("The power of %d is %d",x,multi(x,y)); } int multi (int x, int y) { int ans=0; if(y<=1) return 1; else { ans=(x*multi(x,y-1)); return ans; } }
PLEASE HELP ME IN THIS
Last edited by Ancient Dragon : May 26th, 2008 at 2:37 pm. Reason: add code tags
here's your problem:
it should be:
.
it should be:
c Syntax (Toggle Plain Text)
if(y==1) return x; if(y<=0) return 1;
.
Last edited by jephthah : May 26th, 2008 at 1:09 pm.
Why so serious?
•
•
Join Date: Sep 2006
Posts: 260
Reputation:
Rep Power: 2
Solved Threads: 16
Maybe not. I'd recommend taking initiative even so. It's how students stand out from the rest and it shouldn't be difficult.
http://www.purplemath.com/modules/exponent2.htm
http://www.purplemath.com/modules/exponent2.htm
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:
pretty simple, really.
.
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.
.
Last edited by jephthah : May 28th, 2008 at 3:11 pm.
Why so serious?
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
- Rekursion question and special operators (C++)
- Question about string pattern matching (Java)
- Recursion Search Help (URGENT!) (C)
- Recursion: when do you use it? (C++)
- needed recursion help (C)
- Need help with recursion and arrays (C++)
Other Threads in the C Forum
- Previous Thread: Really quick question on how to keep the cmd window from force closing...
- Next Thread: Error Message "Redifinition of `Struct ...'


Linear Mode