libchm icon

KO urself

libchm | PRO | 07/09/16 06:46:08 PM UTC | 0 ⭐ | 11630 👁️ | Never ⏰ | []
C Intermediate Language |

0 B

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
 
struct node { int key; struct node *next; };
 
int main(int argc, char** argv)
{
    int i, N, M;
    struct node *t, *x;
    
    scanf("%d %d", &N, &M);
    
    t = (struct node *) malloc(sizeof *t);
    t->key = 1; x = t;
    
    for(i = 2; i <= N; i++){
        t->next = (struct node *) malloc(sizeof *t);
        t = t->next;
        t->key = i;
    }
    t->next = x;
    
    while(t != t->next){
        for(i = 1; i < M; i++){ t = t->next;};
        printf("%d", t->next->key);
        x = t->next;
        t->next = t->next->next;
        free(x);
    }
    
    printf("%d\n", t->key);
    
    return 0;
    
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎