C语言的问题,高手帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:47:00
程序的目的是:一组人轮流报数,只报1,2,3,然后接下来的人再从头开始报。报到3的人离队,剩下的人继续报数,直到剩下最后一个人.程序要找到那个人.

怎么写?

我这样写可以吗?

#include<stdio.h>
void solve(int n,int a[])
{int k=0;
int count;
int report=0;
int *p=a;
count=n;
while(count>1)
{if(*(p+k)==1)
{report++;
if(report==3)
{*(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 u the last member.Please enter the amount of your members:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
member[i]=1;
for

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

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;