⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 z.c

📁 课程设计
💻 C
字号:
#include<stdio.h> 
#include<conio.h> 
#include<malloc.h> 
#include<stdlib.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!"); 
getchar(); 
exit(1); 
} 
p=head; 
loop: printf("please input sum number of the monkey:"); 
scanf("%d",&m); 
printf("please input divide number of the monkey:"); 
scanf("%d",&n); 
/******************定义循环链表*************************/
if(n>m)
{printf("Error\n");
printf("Please input again\n");
goto loop; 
}
for(i=0;i<m;i++) 
{ 
q=(struct node *)malloc(sizeof(struct node)); 
if(q==NULL) 
{ 
printf("memorry Error!"); 
getchar(); 
exit(1); 
} 
q->num=i+1; 
p->next=q; 
p=q; 
} 
p->next=head->next; /*链头链尾相连*/ 
/*******************************************************/ 
p=head; 
q=p; 
while(m!=1) 
{ 
i=0; 
while(i!=n) 
{ 
p=q; 
q=q->next; 
i++; 
} 
printf("%-4d",q->num); 
p->next=q->next; 
free(q); 
q=p; 
m--; 
} 
if(n==1) /*当n为1时,最后留在队伍中的肯定是编号最后一个猴子*/ 
p=head->next; 
printf("\nAt last the remain is the king"); 
printf("\nthe king monkey is No.%d's monkey\n",p->num);
free(p); 
free(head); 
getchar(); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -