#include <stdio.h>
#include <stdbool.h>
#include <time.h>

bool is_bouncy(int num);

main()
{
    clock_t begin, end;
    double time_spent;

    begin = clock();
    int count, i;
    count = 0;
    i = 99;
    while (count < (0.99 * i)) {
        i++;
        if (is_bouncy(i))
            count++;
    }
    printf("The answer is %i\n",i);

    end = clock();
    time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    printf("That took %f sec to calculate",time_spent);
}

bool is_bouncy(int num) {
    bool incr, decr;
    int left, right;

    incr = false;
    decr = false;

    right = num % 10;
    num /= 10;
    while (num > 0) {
        left = num % 10;
        if (left < right)
            incr = true;
        else if (left > right)
            decr = true;
        right = left;
        num /= 10;
        if (incr && decr)
            return true;
    }
    return false;
}