30 個人在一條船上,超載,需要 15 人下船。
於是人們排成一隊,排隊的位置即為他們的編號。
報數,從 1 開始,數到 9 的人下船。
如此循環,直到船上僅剩 15 人為止,問都有哪些編號的人下船了呢?
#include<stdio.h> int c = 0; int i = 1; int j = 0; int a[30] = { 0 }; int b[30] = { 0 }; int main() { while (i<=31) { if (i == 31) { i = 1; } else if (c == 15) { break; } else { if (b[i] != 0) { i++; continue; } else { j++; if (j != 9) { i++; continue; } else { b[i] = 1; a[i] = j; j = 0; printf("第%d號下船了\n", i); i++; c++; } } } } }