Add solution for problem 206
This commit is contained in:
38
problem-206.c
Normal file
38
problem-206.c
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user