Advertisement
ledrose

Dinamic massive (homework)

Jan 19th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. struct element {
  7.     int val;
  8.     struct element *p;
  9. };
  10.  
  11. int main(int argc, char *argv[]) {
  12.     struct element *top, *elem;
  13.     int N=10,i;
  14.     elem=(struct element *)malloc(N*sizeof(struct element));
  15.     srand(time(NULL));
  16.    
  17.     for (i=0;i<N-1;i++) {
  18.         (elem+i)->val=rand()%100+1;
  19.         (elem+i)->p=(elem+i+1);
  20.     }
  21.     (elem+N-1)->p=elem;
  22.     top=elem;
  23.    
  24.     while (top) {
  25.         printf("%d",top->val);
  26.         top=top->p;
  27.         getchar();
  28.     }
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement