C语言-耶稣门徒
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<span style="font-family: Arial, Helvetica, sans-serif;">耶稣有15个门徒,其中有一个就是出卖耶稣的叛徒,</span>
<span style="font-family: Arial, Helvetica, sans-serif;">请用排除法找出这位叛徒:15人围坐一圈,从第一个开始报号:1,2,3,1,2,3……,</span>
<span style="font-family: Arial, Helvetica, sans-serif;">凡是报到“3”就退出圈子,最>后留在圈内的人就是出卖耶稣的叛徒,找出它原来的序号。</span>
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 15
#define del_num 3
int main(void)
{
unsigned int buffer[BUFSIZE];
int count = 0;
int number = BUFSIZE;
int i = 0;
for(i=0; i<BUFSIZE;i++){
buffer[i] = i+1;
printf("%d\n",buffer[i]);
}
i=0;
while (number > 1) {
if (buffer[i] != 0) {
count++;
}
if (count == del_num) {
buffer[i] = 0;
number--;
count = 0;
}
i++;
if (i == BUFSIZE) {
i = 0;
}
}
for (i = 0; i < BUFSIZE; i++) {
if (buffer[i] > 0) {
printf("出卖耶稣的叛徒序号是 %d \n", buffer[i]);
}
}
}
微博:https://weibo.com/yangsanchao