diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2014-08-31 20:21:45 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2014-08-31 20:35:09 +0200 |
| commit | 95341b61b030c9e1290f3b326cb7ec584f543aea (patch) | |
| tree | 852386fa04d32eb859bca11c0eff7b5ef9e50f00 /112.c | |
| parent | 571164d977f91925c4c76a292f74f5f93d09ae23 (diff) | |
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; +} + |
