I am having trouble using the pow function in c. The following code:
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
double t;
for(t = 2; t <= 7; t++)
{
double num = pow(7,t);
printf("pi(%d) =", pow(7,t));
}
}
outputs:
pi(1075576832) =pi(807) =pi(431) =pi(53) =pi(701) =pi(323)
instead of outputting pi(49) = pi(7^3) = and so on.
Any help would be much appreciated.
Anton Malyshev
8,9442 gold badges33 silver badges48 bronze badges
1 Answer 1
That's because of wrong modifier. Use %f for double numbers: printf("pi(%f) =", pow(7,t));
answered Sep 22, 2016 at 3:24
Anton Malyshev
8,9442 gold badges33 silver badges48 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-c