blob: bb808bee66698d85fb52525a1adb48fd349a8392 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}
|