Posted: Mon Sep 06, 2010 8:42 pm Post subject: Not being able to use pow()
It's me again.
I was trying to write the code of a binary converter. But I always got strange outputs so I tested my codes and found out that the problem was with the function pow ().
At first I thought it was a variable problem again, but it wasn't! I wrote a new program to test the function and the output was still zero.
code:
#include <math.h>
#include <stdio.h>
int main ()
{
printf ("%d", pow(2,3));
return (0);
}
Thanks for your time.
Sponsor Sponsor
michaelp
Posted: Mon Sep 06, 2010 8:50 pm Post subject: RE:Not being able to use pow()
The format specifier "%d" is for an integer, but the function "pow" returns a double.
So, changing %d to %f will then print "8.000000" (or something similar). Changing that to "%.f" will then just print out 8.
Also, using %d, you can use: