?? 第二題.c
字號(hào):
/* Note:Your choice is C IDE */
#include <stdio.h>
#include <stdlib.h>
typedef struct lnode{
int data;
struct lnode *next;
}LNode;
LNode *Create(int n ){
LNode *s,*p,*t;
int i=1;
t=(LNode *)malloc(sizeof(LNode));
t->data=i; i++;
p=t;
while(n!=1){
s=(LNode *)malloc(sizeof(LNode));
s->data=i;
if(t==NULL)
t=s;
else
p->next=s;
p=s;
i++;
n--;
}
p->next=t;
return (t);
}
LNode* OutNode(LNode *p) {
LNode *q;
for (q=p;q->next!=p;q=q->next);
q->next=p->next;
free (p);
return q;
}
void PrintList(LNode *t,int m,int k){
int i;
LNode *p;
printf ("The out number is:\n");
p=t;
for(i=1;i<k;i++)
p=p->next; /*找到k編號(hào)的節(jié)點(diǎn)指針*/
while (p->next!=p){
for (i=1;i<m;i++)
p=p->next;
printf ("%d ",p->data);
p=OutNode(p);
p=p->next;
}
}
void main(){
int n,k,m,h;
LNode *p,*q;
printf("Please enter 1 to start or -1 to end:");
scanf("%d",&h);
while(h==1){
printf("The total number is:");
scanf("%d",&n);
while(n==0) {
printf("Wrong.");
scanf("%d",&n);
}
printf("The number of the start people is:");
scanf("%d",&k);
while (k>n&&k<1){
printf("Wrong.");
scanf("%d",&k);
}
printf("The interval number is:");
scanf("%d",&m);
while (m>n||m<1){
printf("Wrong.");
scanf("%d",&m);
}
p=Create(n);
PrintList(p,m,k);
puts("Press any key to Quit....");
getch();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -