Largest pallindrome using product of 3digit numbers
#include <stdio.h>
int reverse(int x){
int rev =0;
while(x!=0)
{
int rem = x%10;
rev = rev*10 + rem;
x= x/10;
}
return rev;
}
int main(){
int product,result;
int n1,n2,max=0;
for(n1=999;n1>100;n1--){
for(n2=999;n2>100;n2--){
product = n1 * n2;
result = reverse(product);
if(product == result){
if(product>max){
max = product;
}
}
}
}
printf("Max is %d\n",max);
return 0;
}
//Programmer:TEJAS
Output |
the last 'if' statement is very important to grasp.
ReplyDelete