1

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
asked Sep 22, 2016 at 2:18

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.