RosettaCodeData/Task/Loops-Nested/Bc/loops-nested.bc

47 lines
785 B
Plaintext

s = 1 /* Seed of the random number generator */
/* Random number from 1 to 20. */
define r() {
auto r
while (1) {
/*
* Formula (from POSIX) for random numbers of low
* quality, from 0 to 32767.
*/
s = (s * 1103515245 + 12345) % 4294967296
r = (s / 65536) % 32768
/* Prevent modulo bias. */
if (r >= 32768 % 20) break
}
return ((r % 20) + 1)
}
r = 5 /* Total rows */
c = 5 /* Total columns */
/* Fill array a[] with random numbers from 1 to 20. */
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
a[i * c + j] = r()
}
}
/* Find a 20. */
b = 0
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
v = a[i * c + j]
v /* Print v and a newline. */
if (v == 20) {
b = 1
break
}
}
if (b) break
/* Print "==" and a newline. */
"==
"
}
quit