我看了半天,呵呵,关键本人不才,改了一个地方, 我没有编译环境,不知道这样行唯槐不早侍:
#include
void solve(int n,int a[])
{int k=0;
int count;
int report=0; /* */指睁友
int *p=a; /* 指针指向数组开始 */
count=n;
while(count>1) /* count = N>1*/
{if(*(p+k)==1) /* a[1]==1*/
{report++;
if(report%3==0)
{*(p+k)=0;
count--;
}
}
k++;
if(k==n)
k=0;
}
do
{if(*(p+k)==1)
{printf("The NO.%d member is left.",k+1);
count=0;
}
else
{k++;
if(k==n)
k=0;
}
}
while(count!=0)
}
void main()
{int n,i;
int member[30];
printf("The one who reports 3 will be selected out of the team.This program will show us the last member.Please enter the amount of your members:\n");
scanf("%d",&n); /* 若N=13*/
for(i=0;i
for(;i>=n&&i<30;i++) /* [1,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0...] */
member[i]=0;
solve(n,member);
printf("\n");
}
solve(n,member); void solve(int n,int a[])
函数引用不对,member是数组的首地址,上面你也看到int a[]是个数组,你将它改为int *a;这陵脊样应该可以。
还有一点就是你这个程序写的太乱,看起来真的很吃力。写程序的时候应碰姿该多写注释,这样我们也好更方便的帮你笑汪绝看。
#include
#include
#include
struct Node
{
int data;
struct Node *next;
};
main()
{
struct Node *newnode=NULL;
struct Node *currentnode=NULL;
struct Node *headnode=NULL;
struct Node *a_node;
struct Node *b_node;
int n;
int m;
int i;
printf("please input the number that the person in circle");
scanf("%d",&n);
if(n<=1)
{
printf("input wrong number\n");
exit(1);
}
for(i=1;i<=n;i++)
{
newnode=(struct Node*)malloc(sizeof(struct Node));
newnode->data=i;
if(headnode==NULL)
{
headnode=newnode;
currentnode=newnode;
}
else
{
currentnode->next=newnode;
currentnode=newnode;
}
}
currentnode->next=headnode;
a_node=headnode;
b_node=headnode->胡核next;
printf("please input the number that count to be out ");
scanf("%d"竖滚,&m);
if(m<=1)
{
printf("input wrong number\n");
exit(1);
}
while(a_node!=a_node->next)
{
for(i=1;i
a_node=a_node->next;
b_node=b_node->next;
}
printf("the number %d person out on this turn\n",*b_node);
a_node->next=b_node->next;
a_node=b_node->裤纤掘next;
free(b_node);
b_node=a_node->next;
}
printf("the %d person in circle at last\n",*a_node);
getch();
}