有问题,明显不对。
#include<stdio.h>
#define size 100
void main()
{
int person[size];
int i, j,m;
int arrayLen;
int start=1, overNum;
int deleNum;
int total;
printf( "请输入圆桌上人的总数: " );
scanf( "%d", &arrayLen );
printf( "\n" );
if( ( arrayLen > size ) || ( arrayLen < 0 ) )
{
printf( "超出范围,请重新输入: " );
scanf( "%d", &arrayLen );
printf( "\n" );
}
for( i = 0; i < arrayLen; i++ )
{
person[i] = i+1;
}
printf( "你输入的数据的顺序为: \n" );
for( i = 0; i < arrayLen - 1; i++ )
printf( " %d ==>", person[i] );
printf( "%d \n", person[arrayLen - 1] );
printf( "\n" );
start = start - 1;
printf( "请输入相邻两出列人之间的间隔: " );
scanf( "%d", &overNum );
printf("想让几个人活下来:");
scanf("%d",&m);
printf( "\n" );
total = arrayLen-1;
printf( "程序运行后,出列人的顺序为:\n\n" );
for( i = 0; i < total-m; i++ )
{
if ( arrayLen == m )
printf( "%d", person[0] );
else
{
deleNum = ( start + overNum) % arrayLen; /* 保证循环 */
printf( "%5d", person[deleNum] );
for ( j = deleNum; j < arrayLen; j++ ) /* 将出列元素后面的各元素前移 */
person[j] = person[j+1];
start = deleNum;
arrayLen = arrayLen - 1; /* 移动完毕后,数组长度减1 */
}
}
printf("\n存活下来的人的序号:");
for(i=0;i<m;i++)
printf("%5d",person[i]);
printf( "\n\n" );
}