Largest palindrome product - euler project

后端 未结 15 2089
广开言路
广开言路 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:34

    Done in C. This might help you.

    #include
    int calculate(int n)
    {
        int temp = 0,m = 0;
        m = n;
        while(n != 0)
        {
            temp = temp * 10;
            temp = temp + n % 10;
            n = n / 10;
        }
        if(m == temp)
        {
            printf(" %d \n",temp);
            return temp;
        }
        else
        {
            return 0;
        }
    }
    int main()
    {
        int i,j,temp = 0,count=0,temp1 = 0;
        for(i = 100;i < 1000;i++)
        {
            for(j = 100;j < 1000;j++)
            {
                temp1 = i * j;
                temp = calculate(temp1);
    
                if(temp > count)
                {
                    count = temp;
                }
            }   
        }
        printf(" The Largest Palindrome number is : %d \n",count);
    }
    

提交回复
热议问题