triples.cpp

来自「C++上机课的习题答案」· C++ 代码 · 共 44 行

CPP
44
字号
// triples.cpp
//计算1-100范围内满足沟谷定律的整数. 
//多重循环的使用。 
#include <iostream>

using std::cout;
using std::endl;

int main()
{
   int count = 0;
   long hyptSquared; // hypotenuse squared(直角三角形斜边的平方)
   long sidesSquared; // sides squared(斜边的平方和) 

   for ( /* write header for side1 */ ) {

       for ( /* write header for side2 */ ) {

          for ( /* write header for hyptSquared */ ) {
             /* calculate hyptSquared */
             /* calculate the sum of the sides squared */

             if ( hyptSquared == sidesSquared ) {
                cout << side1 << "\t" << side2 << "\t"
                     << hypt << "\n";
                ++count;

             } // end if

          } // end for

       } // end for

   } // end for

   cout << "A total of " << count << " triples were found."
        << endl;

   system("PAUSE");
   return 0;

} // end main

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?