//用数组实现约瑟夫环
#include
#define maxN 100
int main(){
int Joself_k(int,int,int);
int n,k,m;
printf("输入总人数n,开始报数号k,出列号码m:\n");
scanf("%d%d%d",&n,&k,&m);
Joself_k(n,k,m);
return 0;
}
int Joself_k(int n,int k,int m){
//从编号k(k<=n)开始报数,报数到m的出列
int i,j,count=1,a[maxN];
for(i=0;i
printf("出列序列:\n");
while(n>=1){
count++;//报数
i=(i+1)%n;//循环时使得i值小于n
if(count==m){
printf("%d\t",a[i]);
for(j=i;j
n--;
count=1;
}
}
printf("\n");
return(a[0]);
}