Advertisement
wowonline

Untitled

Dec 20th, 2021
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     FILE *finput = fopen("matrix.in", "rb");
  6.     FILE *foutput = fopen("trace.out", "wb");
  7.  
  8.     short int size;
  9.     int byte, number, step = 1;
  10.     fread(&byte, 1, 1, finput);
  11.     size = byte * 256;
  12.     fread(&byte, 1, 1, finput);
  13.     size += byte;
  14.     long long trace = 0;
  15.  
  16.    
  17.     for (int i = 0; i < size; i++)
  18.     {
  19.         for (int j = 0; j < size; j++)
  20.         {
  21.             number = 0;
  22.             for (int h = 0; h < 4; h++)
  23.             {
  24.                 fread(&byte, 1, 1, finput);
  25.                 number *= 256;
  26.                 number += byte;
  27.             }
  28.             if (step % (size+1) == 1)
  29.             {
  30.                 trace += number;
  31.             }
  32.             step++;
  33.         }
  34.     }
  35.  
  36.     fwrite(&trace, sizeof(long long int), 1, foutput);
  37.     fclose(finput);
  38.     fclose(foutput);
  39.  
  40.     FILE *finput1 = fopen("trace.out", "rb");
  41.    
  42.     int array[8];
  43.     for (int i = 0; i < 8; i++)
  44.     {
  45.         fread(&array[i], 1, 1, finput1);
  46.     }
  47.     fclose(finput1);
  48.     FILE *finput2 = fopen("trace.out", "wb");
  49.     for (int i = 7; i >= 0; i--)
  50.     {
  51.         fwrite(&array[i], 1, 1, finput2);
  52.     }
  53.  
  54.     fclose(finput2);
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement