/*
选候王程序(数组操作~~)
题目:一共有50只猴子,编号从1-50,从第一只猴子开始1-7数数,数到7的猴子出来,从下一只猴子开始循环数数
直到最后一只猴子就是猴王
author:calm
*/
#include<stdio.h>
#define N 50
void main()
{
int i=0,j=0,monkey[N],b,n=N;
for(i=0;i<N;i++)
{
monkey[i]=i+1;
}
printf("Monkeys:");
for(i=0;i<N;i++)
{
printf("%d ",monkey[i]);
}
i=0;
printf("\nAny key to choose the king...");
getch();
while(i<N)
{
if(monkey[i]>0)
{
if(1==n)
{
b=monkey[i];
break;
}
j++;
if(7==j)
{
b=monkey[i];
monkey[i]=0;
j=0;
n--;
printf("\n#The %d is deleted!",b);
}
}
i++;
i=i%N;
}
printf("\n#The king is: %d\n",b);
getchar();
}