Making a square() function without x*x in C++

后端 未结 7 2093
攒了一身酷
攒了一身酷 2020-12-31 14:44

I am self-studying C++ and the book \"Programming-Principles and Practices Using C++\" by Bjarne Stroustrup. One of the \"Try This\" asks this:

Implement square() wi

相关标签:
7条回答
  • 2020-12-31 15:42
    int square(int x)
    {
        int result = 0;
        for (int counter = 0; counter < x; ++counter) result += x;
        return result;
    }
    
    0 讨论(0)
提交回复
热议问题