Files
project-euler/problem-206.c
2019-03-03 01:55:58 -05:00

39 lines
566 B
C

#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define MIN_NUM 1020304050607080900
#define MAX_NUM 1929394959697989990
int digits[10] = {0, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int check(long num) {
int rem;
int i = 0;
while (num>0) {
rem = num % 10;
if (rem != digits[i])
return FALSE;
num /= 100;
i++;
}
return TRUE;
}
int main(int argc, char **argv) {
long i = 1;
while ((i*i) < MIN_NUM) i++;
while ((i*i) < MAX_NUM) {
if (check(i*i))
break;
i++;
}
printf("The unique integer is %ld and it's square is %ld\n", i, i*i);
return 0;
}