Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created November 10, 2014 02:23
Show Gist options
  • Save shohan4556/028a79859f7f6a5b350b to your computer and use it in GitHub Desktop.
Save shohan4556/028a79859f7f6a5b350b to your computer and use it in GitHub Desktop.
project euler problem 04
#include<stdio.h>
int reverse(int n){
int reversed=0;
while(n>0){
reversed=10*reversed+(n%10);
n=n/10;
}
return reversed;
}
int is_pal(int n){
if(n==reverse(n))
return n;
else
return 0;
}
int main()
{
int lar_pal=0;
int a=999;int b;
while(a>100){
b=999;
while(b>=a){
if(a*b<=lar_pal)
break;
if(is_pal(a*b))
lar_pal=a*b;
b--;
}
a--;
}
printf("%d\n",lar_pal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment