| | |
How to perform pow(x,y) where x and y are floats??
![]() |
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.
<< moderator edit: added
I'll be glad if you help me out.
Thanks
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.
C Syntax (Toggle Plain Text)
//Program to raise a number to power when both are floating nos #include<stdio.h> #include<conio.h> #include<math.h> void power(float x,float i) { float y; y=pow(x,i); printf("%d",y); } void main() { float x,i; printf("Enter any number"); scanf("%d",&x); printf("Enter its power"); scanf("%d",&i); power(x,i); }
[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.
•
•
Join Date: Aug 2005
Posts: 80
Reputation:
Solved Threads: 2
•
•
•
•
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.
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
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
C Syntax (Toggle Plain Text)
This file: #include <math.h> int main(int argc, char *argv[]) { printf("%f\n",pow(2., 3.5) ); return 0; } compiled this way (This is unix does not matter) kcsdev:/home/jmcnama> cc t.c -lm Gives this result: kcsdev:/home/jmcnama> a.out 11.313708
![]() |
Similar Threads
- Error trying to perform single word searches in address bar. (Viruses, Spyware and other Nasties)
- Arrays (C++)
- Mortgage Program help (Java)
- How to Perform Disk Error Checking in Windows XP (Windows tips 'n' tweaks)
- Perform a Repair Installation (Windows tips 'n' tweaks)
Other Threads in the C Forum
- Previous Thread: Saving to a file
- Next Thread: CString Lenght
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h





