#include <stdio.h>
#define N 60000
void oper(int *,int,int);
int main(int argc, char *argv[])
{
int arr[N],i,n;
int *p;
printf("the all persion is count:");
scanf("%d",&n);
for (p = arr,i = 0; i < n; i++)
{
*p++ = i + 1;
}
p = arr;
oper(p,n,3);
system("pause");
return 0;
}
void oper(int *arr,int n,int num)
{
int *p,*p_begin,*p_end;
int count = 0,k = 0;
p_begin = arr;
p_end = arr + n;
p = p_begin;
do
{
if (*p != 0 )
{
k ++;
}
if (k == num)
{
if (count + 1 == n) //when the remove element is last one ,break circle.
{
break;
}
else
{
printf("remove number : %d \n",*p); // printf remove info.
*p = 0; //set point element is 0.
k = 0; //counter reset 0.
count ++;
}
}
p++;
if (p == p_end)
{
p = p_begin;
}
}while(1);
printf("\nthe result number : %d\n",*p);
}
|