943,972 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 6891
  • C RSS
Nov 18th, 2005
0

How to perform pow(x,y) where x and y are floats??

Expand Post »
Hi everyone,
I am having this problem to define a function which raises a float y eg 3.5 which is not a whole number to the base x.
Heres the code which gives domain error as function pow takes only int values.
  1. //Program to raise a number to power when both are floating nos
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<math.h>
  5. void power(float x,float i)
  6. {
  7. float y;
  8. y=pow(x,i);
  9. printf("%d",y);
  10. }
  11.  
  12. void main()
  13. {
  14. float x,i;
  15. printf("Enter any number");
  16. scanf("%d",&x);
  17. printf("Enter its power");
  18. scanf("%d",&i);
  19. power(x,i);
  20. }
<< moderator edit: added [code][/code] tags >>

I'll be glad if you help me out.
Thanks
Last edited by Dave Sinkula; Nov 18th, 2005 at 7:03 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
comwizz is offline Offline
39 posts
since Nov 2005
Nov 18th, 2005
0

Re: How to perform pow(x,y) where x and y are floats??

SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Nov 18th, 2005
0

Re: How to perform pow(x,y) where x and y are floats??

Quote originally posted by comwizz ...
I am having this problem to define a function which raises a float y eg 3.5 which is not a whole number to the base x.
Heres the code which gives domain error as function pow takes only int values.
http://www.cplusplus.com/ref/cmath/pow.html

Pow, in the standard C library for mathematical operations, takes two double values by default. You could also look into the powerful powf function.

-Fredric
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005
Nov 18th, 2005
0

Re: How to perform pow(x,y) where x and y are floats??

I want to run this program in C where I can compute 2^(3.5).Is this possible in C?
Reputation Points: 10
Solved Threads: 0
Light Poster
comwizz is offline Offline
39 posts
since Nov 2005
Nov 18th, 2005
0

Re: How to perform pow(x,y) where x and y are floats??

  1. This file:
  2. #include <math.h>
  3. int main(int argc, char *argv[])
  4. {
  5. printf("%f\n",pow(2., 3.5) );
  6. return 0;
  7. }
  8. compiled this way (This is unix does not matter)
  9. kcsdev:/home/jmcnama> cc t.c -lm
  10. Gives this result:
  11. kcsdev:/home/jmcnama> a.out
  12. 11.313708
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Saving to a file
Next Thread in C Forum Timeline: CString Lenght





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC