#include<stdio.h>
void LastNum(int *Arr, int n)
{
int qw = 0; //圈外的人数
int count = 0; //报数计数器
int i = 0;
for (i = 0; i < n; i++)
{
Arr[i] = i + 1; //给这n个人编号
}
printf ("out number is : ");
i = 0;
while (qw < n - 1) //圈外人数达到4个就退出,由于圈外由0开始,所以到n-1结束
{
if (Arr[i])
{
count++;
}
if (count == 3)
{
printf ("%d ", Arr[i]); //当报数到3那就把当前的人置0
Arr[i] = 0;
qw++;
count = 0;
}
i++;
if (i == n) //开始下一圈
{
i = 0;
}
}
printf ("\n");
}
int main()
{
int n = 0;
printf("please input a number(2~n):");
scanf("%d",&n);
LastNum(array, n);
for(i = 0;i < n; i++)
{
if(array[i])
{
printf("\nthe last number is %d\n", array[i]); //找到最后一个人的编号
}
}
return 0 ;
}
void LastNum(int *Arr, int n)
{
int qw = 0; //圈外的人数
int count = 0; //报数计数器
int i = 0;
for (i = 0; i < n; i++)
{
Arr[i] = i + 1; //给这n个人编号
}
printf ("out number is : ");
i = 0;
while (qw < n - 1) //圈外人数达到4个就退出,由于圈外由0开始,所以到n-1结束
{
if (Arr[i])
{
count++;
}
if (count == 3)
{
printf ("%d ", Arr[i]); //当报数到3那就把当前的人置0
Arr[i] = 0;
qw++;
count = 0;
}
i++;
if (i == n) //开始下一圈
{
i = 0;
}
}
printf ("\n");
}
int main()
{
int n = 0;
int i = 0;
int array[1024] = {0};
printf("please input a number(2~n):");
scanf("%d",&n);
LastNum(array, n);
for(i = 0;i < n; i++)
{
if(array[i])
{
printf("\nthe last number is %d\n", array[i]); //找到最后一个人的编号
}
}
return 0 ;
}