-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler0004.c
44 lines (41 loc) · 869 Bytes
/
euler0004.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//projecteuler.net/problem=4
#include <stdio.h>
int main()
{
int num=538835;
int orignum=num;
int digit[8];
int counter=0;
int multinum=1;
int b;
printf("Given input is %d\n", num);
//deconstruct digits
while(num>0) {
digit[counter]=num%10;
printf("%d\n",digit[counter]);
num/=10;
counter++;
}
//figure out required multiplication for reconstruct
if(counter>0){
for(b=1;b<counter;b++){
multinum=multinum*10;
}
}
//reconstruct digits to number
int i=0;
int reconnum=0;
while(i<counter) {
reconnum+=digit[i]*multinum;
multinum/=10;
i++;
}
printf("Reconstructed to: %d\n",reconnum);
if(reconnum==orignum) {
printf("Yes, this is a palindrome");
}
else{
printf("No, this is NOT a palindrome");
}
return 0;
}