Why is my power operator (^) not working?

前端 未结 8 1322
半阙折子戏
半阙折子戏 2020-11-22 02:12
#include 

void main(void)
{
    int a;
    int result;
    int sum = 0;
    printf(\"Enter a number: \");
    scanf(\"%d\", &a);
    for( int i =         


        
8条回答
  •  情深已故
    2020-11-22 03:03

    pow() doesn't work with int, hence the error "error C2668:'pow': ambiguous call to overloaded function"

    http://www.cplusplus.com/reference/clibrary/cmath/pow/

    Write your own power function for ints:

    int power(int base, int exp)
    {
        int result = 1;
        while(exp) { result *= base; exp--; }
        return result;
    }
    

提交回复
热议问题