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.
cevap: 906609
#include <stdio.h>
#include <math.h>
#pragma hdrstop
#include <tchar.h>
// global degiskenler
unsigned int carpim;
unsigned char terslendi = 0; // todo : bunun ismini degistir
unsigned int basamak_sayisi;
unsigned int mod;
unsigned int carpan_1;
unsigned int carpan_2;
unsigned int *basamaklar;
// fonksiyon prototipleri
void carpma();
unsigned char tersleniyormu(unsigned int);
unsigned int basamak_sayisi_hesapla(unsigned int);
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
carpma();
system("pause");
}
void carpma()
{
for (carpan_1 = 100; carpan_1 < 1000; carpan_1++) {
for (carpan_2 = 100; carpan_2 < 1000; carpan_2++) {
carpim = carpan_1 * carpan_2;
terslendi = tersleniyormu(carpim);
// tum terslenen sayilari ekrana bas
if (!terslendi) {
printf("terslenebilen carpimlar = %d\n",carpim);
}
}
}
return carpim;
}
unsigned char tersleniyormu(unsigned int carpim)
{
unsigned int i;
basamak_sayisi = basamak_sayisi_hesapla(carpim);
basamaklar = (unsigned int *) calloc(basamak_sayisi, sizeof(unsigned int));
for (i = 0; i < basamak_sayisi; i++) {
mod = fmod(carpim, 10);
carpim = carpim/10;
basamaklar[i] = mod;
}
terslendi = basamak_sayisi/2;
for (i = 0; i < (basamak_sayisi/2); i++) {
if (basamaklar[basamak_sayisi-i-1] == basamaklar[i]) {
terslendi = terslendi - 1;
}
}
return terslendi;
}
unsigned int basamak_sayisi_hesapla(unsigned int sayi)
{
float log_f;
unsigned int log_i;
log_f = log10(sayi); // float logaritma
log_i = floor(log_f); // integer logaritma
basamak_sayisi = log_i + 1;
return basamak_sayisi;
}