How does the function pow work?

前端 未结 2 1086
温柔的废话
温柔的废话 2021-01-23 04:52

After compiling the following program I get the output \"2346\" but was expecting \"2345\".

#include
#include
int nr_cif(int a)
{         


        
2条回答
  •  情书的邮戳
    2021-01-23 05:20

    I'm not amazing or great at math but this seems to work: http://ideone.com/dFsODB

    #include 
    #include 
    
    float mypow(float value, int pow)
    {
        float temp = value;
        for (int i = 0; i < pow - 1; ++i)
            temp *= value;
    
        for (int i = 0; i > pow - 1; --i)
            temp /= value;
    
        return temp;
    }
    
    
    int main() 
    {
        std::cout<

提交回复
热议问题