luluinstalock

Untitled

Jan 25th, 2016
288
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. struct Node{
  6.     int x;
  7.     struct Node *next;
  8. };
  9.  
  10. int main(){
  11.     srand(time(NULL));
  12.     struct Node *start;
  13.     start = malloc(sizeof(struct Node));
  14.    
  15.     start->x=(rand() % 10 - 1);
  16.  
  17.     printf("%d", start->x);
  18.    
  19.     struct Node *last;
  20.     last = start;
  21.    
  22.     struct Node *tmp;
  23.     tmp = malloc(sizeof(struct Node));
  24.    
  25.     for (int i=0; i<9; i++){
  26.        
  27.    
  28.         tmp->x=(rand() % 10 - 1);
  29.    
  30.         last->next = tmp;
  31.         tmp->next = NULL;
  32.         last=tmp;
  33.        
  34.         printf("%d", tmp->x);
  35.     }
  36.     free(start);
  37.     free(tmp);
  38.     return 0;
  39. }
RAW Paste Data