C++語言 同構數 求1000以內的同構數


同構數

同構數是會出現在它的平方的右邊的數。如5×5=25,6×6=36。

例子:求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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM