同构数

同构数是会出现在它的平方的右边的数。如5×5=25,6×6=36。

C++语言 同构数 求1000以内的同构数

例子:求1000以内的同构数

#include <iostream>
#include <cmath> //数学函数
#define N 1000 //定义常量

using namespace std; //引用名字空间

//求1000以内的同构数 转自http://www.pythonschool.com/蟒蛇学校
int main(int argc, char* argv[])
{
    long result;
    cout << "<------------1~1000之间的同构数----------->"<<endl;
    for( int i=N; i>=1; i-- )
    {
        result = pow(i,2);
        if( i<10 && i == result%10 ) //处理10以下的数
            cout << i << "    同构数   " << result << endl;
        else if( i>=10 && i == result%100 ) //处理100以下的数
            cout << i << "   同构数   " << result << endl;
        else if( i>=100 && i == result%1000 ) //处理1000以下的数
            cout << i << "  同构数   " << result << endl;
        else
            continue;
    }
    cout<<"<--------------------------------------->"<<endl;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-07-13
猜你喜欢
  • 2021-11-17
  • 2021-04-08
  • 2022-12-23
  • 2021-10-24
  • 2021-08-21
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案