#include <stdio.h>
float pows(float,float);
int main()
{
float num,base;
printf("enter base followed by power integer.");
scanf("%f %f",&base,&num);
printf("%f ",pows(base,num));
return 0;
}
float pows(float base,float n)
{
if(n==0)
return(1);
else if(base==0)
return(0);
else
for(;n>=1;n--)
{ return(base*pows(base,n-1));/*recursive*/
}
}
D33wakar
36
Posting Whiz in Training
Recommended Answers
Jump to PostOther than it doesn't work properly, do you have a question? Or is this an ego-post?
Jump to Post%f and float n does not look integer to me, like your prompt and algorithm suggests.
Jump to PostAlso you are doing both iteration and recursion same time, chose which one.
Jump to PostYour algorithm can not deal with fractions, so you should take long, not float argument. But I doubt that C can deal with bigger than int range of powers if you are not dealing with very small numbers (which also would could take quite a while as you are recursing …
Jump to Postlooking for advice).
Then why didn't you say so? Posting only code says "Look at my code! Ain't it great?" That's an ego-post. If you simply added "I'm looking for advice on making this code better" you would get more useful responses right away.
All 23 Replies
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
TrustyTony
888
pyMod
Team Colleague
Featured Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
D33wakar
36
Posting Whiz in Training
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
D33wakar
36
Posting Whiz in Training
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
D33wakar
36
Posting Whiz in Training
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.