problem:
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.
বাংলা প্রবলেম, তবে একটা সমস্যা execution time অনেক বেড়ে যাবে যদি লুপ দিয়ে করেন। যাই হোক নিচের কোডটি যথেষ্ট efficient।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |