A fundamental problem. Just to review some stuff.
1 #include<stdio.h>
2 #include<stdlib.h>
3
4 struct node{
5 int value;
6 struct node* next;
7 };
8 typedef struct node NODE;
9 typedef NODE* NODEPTR;
10
11 int main()
12 {
13 int i;
14 int count;
15 int N,M;
16 NODEPTR head=(NODEPTR)malloc(sizeof(NODE));
17 NODEPTR prePtr=head;
18 NODEPTR currPtr;
19 NODEPTR temp;
20
21 scanf("%d %d",&N,&M);
22 count=N;
23
24 for(i=1;i<=N;i++)
25 {
26 currPtr=(NODEPTR)malloc(sizeof(NODE));
27 currPtr->value=i;
28 prePtr->next=currPtr;
29 prePtr=currPtr;
30 }
31
32 currPtr->next=head->next;
33 currPtr=head->next;
34
35 while(count--)
36 {
37 for(i=1;i<=M-2;i++)
38 currPtr=currPtr->next;
39
40 temp=currPtr->next;
41 printf("%d is out\n",temp->value);
42 currPtr->next=temp->next;
43 currPtr=currPtr->next;
44 free(temp);
45 }
46
47
48 return 0;
49 }
50