diff options
Diffstat (limited to '112.c')
| -rw-r--r-- | 112.c | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ + +int isbouncy(unsigned long n) +{ + char increasing=1, decreasing=1; + char lastdigit = n % 10; + n /= 10; + + while(n > 0) + { + char digit = n % 10; + if(digit > lastdigit) + increasing = 0; + else if(digit < lastdigit) + decreasing = 0; + + if(increasing == 0 && decreasing == 0) + return 1; + + lastdigit = digit; + n /= 10; + } + return 0; +} + +int main(void) +{ + unsigned long n = 100; + unsigned long bouncycount = 0; + double ratio; + + while(1) + { + if(isbouncy(++n)) + bouncycount++; + + ratio = (double)bouncycount/n; + if(ratio == 0.99) + break; + + } + printf("%ld\n", n); + + return 0; +} + |
