谁能帮我做一下着道程序题啊??谢谢!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/20 10:14:26
6、猴子选大王:
① N 只猴子站成一行,每隔 M 只从头到尾报数,反复进行,报过数的退出,打印每次退出的猴子的编号,直到剩下一只为止。
② N 只猴子站成一行,每 M 只报数。先从头到尾,报到尾后,再返回从尾到头报数,打印每次方向及过程,直到剩下二只时,以排到后面的(指报数方向)为大王。
③ N 只猴子围成一圈,从第 P 个开始,每隔 M 只报数,打印每次过程,只剩下一个时为大王。

要求:1、给出程序的实现思想
2、给出程序流程图
3、提交程序源代码
4、给出程序运行结果

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

struct node
{
int num;
struct node *next;
};

void main()
{
int n=0;
int m=0;
int i=0;
struct node *head,*p,*q;
head=(struct node *)malloc(sizeof(struct node));
if(head==NULL)
{
printf("memorry Error!");
getch();
exit(1);
}
p=head;
clrscr();
printf("please input number1:");
scanf("%d",&m);
printf("please input number2:");
scanf("%d",&n);
/******************定义循环链表*************************/
for(i=0;i<m;i++)
{
q=(struct node *)malloc(sizeof(struct node));
if(q==NULL)
{
printf("memorry Error!");
getch();
exit(1);