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

Reply

Join Date: Nov 2005
Posts: 39
Reputation: comwizz is an unknown quantity at this point 
Solved Threads: 0
comwizz's Avatar
comwizz comwizz is offline Offline
Light Poster

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

 
0
  #1
Nov 18th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

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

 
0
  #2
Nov 18th, 2005
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 80
Reputation: Daishi is an unknown quantity at this point 
Solved Threads: 2
Daishi Daishi is offline Offline
Junior Poster in Training

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

 
0
  #3
Nov 18th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 39
Reputation: comwizz is an unknown quantity at this point 
Solved Threads: 0
comwizz's Avatar
comwizz comwizz is offline Offline
Light Poster

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

 
0
  #4
Nov 18th, 2005
I want to run this program in C where I can compute 2^(3.5).Is this possible in C?
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

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

 
0
  #5
Nov 18th, 2005
  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC