其他分享
首页 > 其他分享> > C语言绕圈报数

C语言绕圈报数

作者:互联网

//有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,
//问最后留下的是原来第几号的那位
//有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数

#include <stdio.h>

int main()
{                  
	int people[100];
	int n = 0;
	scanf("%d", &n);
	int i = 0;
	for (i = i; i < n; i++)
	{
		people[i] = i + 1;
	}
	int remain = n;
	int count = 0;
	int *p = NULL;
	while (remain > 1)
	{
		p = people;
		while (p!=people+n)
		{
			if ((*p) != 0)
			{
				count++;
				if (count == 3)
				{
					count = 0;
					*p = 0;
					remain--;
				}
			}
			p++;
		}

	}
	for (int i = 0; i < n; i++) {
		if (people[i] != 0) {
			printf("%d", people[i]);
		}
	}
	return 0;
}

标签:count,people,int,C语言,++,remain,绕圈,报数
来源: https://blog.csdn.net/weixin_44876693/article/details/122782654