daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. FILE *input, *output;
  4.  
  5. int min(int a, int b) {
  6.     return (a > b) ? b : a;
  7. }
  8.  
  9. int main(void) {
  10.     input = fopen("input.bin", "rb");
  11.     output = fopen("output.bin", "wb");
  12.     int n;
  13.     int num[2];
  14.     fread(&n, sizeof(int), 1, input);
  15.     for (int i = 0; i < n; i++) {
  16.         fread(&num, sizeof(int), 2, input);
  17.         for (int i = min(num[0], num[1]); i > 0; i--) {
  18.             if (num[0] % i == 0 && num[1] % i == 0) {
  19.                 num[0] /= i;
  20.                 num[1] /= i;
  21.                 fwrite(num, sizeof(int), 2, output);
  22.                 break;
  23.             }
  24.         }
  25.     }
  26.     fclose(input);
  27.     fclose(output);
  28.     return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top