code blocks power function is not working in c

前端 未结 5 841
陌清茗
陌清茗 2021-01-26 19:47

i am using code block for learning c. my code is

#include
#include
int main()
{
  int x;
  x = pow(5,2);
  printf(\"%d\", x);
}

Out         


        
5条回答
  •  不要未来只要你来
    2021-01-26 20:42

    Try changing initialization to this:

    int x=-1 ,i=-1 ,j=-1;
    

    And last print to this:

    printf("pow(%d, %d) == %d\n", i, j, x);
    

    That should give good hint about the problem. Also, check return values of scanf, they should return number of items read, ie. 1 with code above.

    It's almost certain, that you entered invalid input for scanf, and i or j were left uninitialized, and that 24 is just garbage value.

    Also, compile with warnings enabled, and fix them (like, add return 0; to end of main).

提交回复
热议问题