int solution() { int n, count = 0; double pct; for (n=100; ; n++) { if (is_bouncy(n)) { count++; pct = 100.0 * count / n; if (pct == 99.0) return n; } } }
int main(){ //We know the first 99 numbers are non-bouncy int i, bouncy = 0, non_bouncy = 99; //Until the ratio is reached for (i = 100; !is_ratio_reached(bouncy, non_bouncy); i++){ //Add numbers to the counts if (is_bouncy(i)){ bouncy++; } else{ non_bouncy++; } } //Subtract one from the result to compensate for the last increment in the for loop printf("The first number that satisfies the condition is %i\n", i-1); return 0; }