Add solution for problem 206

This commit is contained in:
kevin
2019-03-03 01:55:58 -05:00
parent fe22240e29
commit a73040bc67

38
problem-206.c Normal file
View File

@@ -0,0 +1,38 @@
#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;
}