nguyentruong98

Untitled

Dec 12th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. int bai2()
  2. {
  3.       int gate = 0;
  4.       int i,j;
  5.       int x,y;
  6.       FILE *f;
  7.       f = fopen("data1.txt", "r");
  8.       if (f == NULL)
  9.       {
  10.             printf("ERROR\n");
  11.       }
  12.       else
  13.       {
  14.             fscanf(f, "%d", &n);
  15.       }
  16.       for (i = 1; i <= n; i++)
  17.       {
  18.             for (j = 1; j <= n; j++)
  19.             {
  20.                   fscanf(f, "%d", &matrix[i][j]);
  21.                   printf("map[%d][%d] = %d\n", i, j, matrix[i][j]);
  22.             }
  23.       }
  24.             for(y=1; y<=n; y++){
  25.                   if(matrix[1][1] == 0)
  26.                   gate = gate + 0.5;
  27.                   if(matrix[1][6] == 0)
  28.                   gate = gate + 0.5;
  29.                   if(matrix[1][y] == 0)
  30.                   gate = gate +1;
  31.                   if(matrix[6][y] == 0)
  32.                   gate = gate +1;
  33.             }
  34.             for(x=1; x<=n; x++){
  35.                   if(matrix[1][1] == 0)
  36.                   gate = gate + 0.5;
  37.                   if(matrix[6][1] == 0)
  38.                   gate = gate + 0.5;
  39.                   if(matrix[x][1] == 0)
  40.                   gate = gate +1;
  41.                   if(matrix[x][6] == 0)
  42.                   gate = gate +1;
  43.             }
  44.       printf("%d\n", gate);
  45.       return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment