Largest palindrome product - euler project

后端 未结 15 1946
广开言路
广开言路 2020-12-10 22:05

I was trying to solve project Euler problem 4 which is:

A palindromic number reads the same both ways. The largest palindrome made from the product of tw

15条回答
  •  囚心锁ツ
    2020-12-10 22:46

    Here is the code in c++

    #include 
    using namespace std;
    int reverse(int a){
    int reverse=0;
    for(int i=0;i<6;i++){
        reverse = reverse*10+a%10;
        a/=10;
    }
    return reverse;
    }
    int main(){
    int a=999,max=1,rev;;
    int b=999;
    for(a=999;a>100;a--){
        for(b=999;b>100;b--){
            int p = a*b;
             rev = reverse(p);
            if (p==rev) {
                if(max

提交回复
热议问题