From 95341b61b030c9e1290f3b326cb7ec584f543aea Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 31 Aug 2014 20:21:45 +0200 Subject: moved files to higher directory after split to new repository --- 112.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 112.c (limited to '112.c') diff --git a/112.c b/112.c new file mode 100644 index 0000000..bb808be --- /dev/null +++ b/112.c @@ -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; +} + -- cgit v1.2.3