## Posted By

mju4t on 02/06/11

# Project Euler Problem 4

/ Published in: C++

`/*Alexander DeTrano2/1/2010Project Euler - Problem 4 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91  99. Find the largest palindrome made from the product of two 3-digit numbers.*/#include <iostream>#include <vector>#include <algorithm>using namespace std;int palindromecheck(int n); int main(){    vector<int> myArray;    int num=0; int count=0;    for(int i=1;i<=999;i++){        for(int j=1;j<=999;j++){            num=i*j;        if(palindromecheck(num)==1){            myArray.push_back(count); //expand size of array by 1            myArray[count]=num;            count+=1;        }         }    }cout<<myArray.size(); //#of elements before removing duplicatssort(myArray.begin(),myArray.end()); //sort vector from small to largemyArray.erase(unique(myArray.begin(),myArray.end()),myArray.end()); //erase duplicatescout<<myArray.size()<<endl; //print new size of arraycout<<"Max Palindrome is: "<<*(max_element( myArray.begin(), myArray.end() ) ); //find max element in array return 0;}  int palindromecheck(int n){    int r,sum=0,temp,flag;    temp=n;    while(n){        r=n%10;        n=n/10;        sum=sum*10+r;    }     if(temp==sum)    flag=1;    else    flag=0;    return flag;}`

You need to login to post a comment.