Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
46
Task/Loops-Nested/Bc/loops-nested.bc
Normal file
46
Task/Loops-Nested/Bc/loops-nested.bc
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue