summaryrefslogtreecommitdiff
path: root/112.c
diff options
context:
space:
mode:
Diffstat (limited to '112.c')
-rw-r--r--112.c45
1 files changed, 45 insertions, 0 deletions
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;
+}
+