A classic puzzle: for a whole number x, x + 100 is a perfect square and x + 268 is too. What is x? Find every answer from 0 to 10000, smallest first, one per line. For example 21: 21 + 100 = 121 = 11², 21 + 268 = 289 = 17². is_square(v) is already written and returns true if v is a perfect square.
21 261 1581
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
bool is_square(int v) {
int r = (int)sqrt(v);
return r * r == v;
}
int main(void) {
for (int x = 0; x <= 10000; x++) {
// your code here: if x + 100 and x + 268 are both squares, show x
}
return 0;
}
Run tries the examples. When they look right, Submit.