Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. struct element {
  6.     int elem, nord, south, east, west; //, check;
  7. };
  8. int** m;
  9. int* vect;
  10. int n,k;
  11. struct element a;
  12. struct element first;
  13.  
  14. int main(int argc, char** argv) {
  15.  int i,j;
  16.  n = 6;//atoi(argv[1]);
  17. // k = atoi(argv[2]);
  18.  m = (int**)malloc(n*sizeof(int));
  19.  for(i=0;i<n;i++){
  20.      m[i] =malloc(n*sizeof(int));
  21.      for(j=0;j<n;j++){
  22.      m[i][j] = rand()%100;
  23.      printf("%d ",m[i][j]);
  24.      }
  25.      printf("\n");
  26.  }
  27.  
  28. a = (struct element*) malloc(n*sizeof(struct element));
  29.  for (i=0;i<n;i++){
  30.    for(j=0;j<n;j++) {
  31.         a[i]->elem = m[i][j]; //31
  32.     if (i==1) a[i]->nord = -1; //32
  33.      else a[i]->nord =  m[i-1][j]; //33
  34.     if(i==n) a[i]->south = -1; //34
  35.       else a[i]->south = m[i+1][j]; //35
  36.     if(j==1) a[i]->west = -1; //36
  37.      else a[i]->west = m[i,j-1]; //37
  38.     if (j==n) a[i]->east = -1;
  39.      else a[i]->east = m[i,j+1];
  40.     }
  41.  }
  42.  first = (struct element*)malloc(sizeof(struct element));
  43.  first.elem = a[1];
  44.  
  45.  
  46.  return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement