c语言题,求大神看看哪错了?怎么改?

2025年03月23日 05:54
有1个网友回答
网友(1):

你的程序就不看了。问题太多,首先count=m,进入while 就开始判断if(count == m) 就不对。应该定义count=0。按照你的思路帮你写了一个,你把这个问题弄得有点复杂了。其实这是个双向回环链表的问题。你把双向回环链表搞明白了,这个就太简单了
int main()
{
int n,m;
scanf("%d %d", &n, &m);
CountOff( n, m);
return 0;
}
void CountOff( int n, int m){
int index=0;

int step = n;
int countNum=0;

int arry[n];
int i = 0;
for(i = 0;iarry[i]=1;

while(step >1)
{
if(arry[index] == 1)
{
countNum++;

if(countNum == m)
{
countNum = 0;
arry[index] = 0;
// 这个输出的就是退出的顺序,你可以把index保存起来。在整个输出也可以
printf("%d ",index);
step--;
}
}
index++;

if(index == n)
index=0;
}
printf("\n");
}