Advertisement
STANAANDREY

sb prog 11

Feb 23rd, 2022
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("text.in");
  5. ofstream fout("text.out");
  6. int n, v[100];
  7.  
  8. void read(int &n, int v[]) {
  9.     fin >> n;
  10.     for (int i = 0; i < n; i++) {
  11.         fin >> v[i];
  12.     }
  13. }
  14.  
  15. int getGcd(int a, int b) {
  16.     while (a != b) {
  17.         if (a > b) {
  18.             a -= b;
  19.         } else {
  20.             b -= a;
  21.         }
  22.     }
  23.     return a;
  24. }
  25.  
  26. int main() {
  27.     read(n, v);
  28.     int r = v[0];
  29.     for (int i = 1; i < n; i++) {
  30.         r = getGcd(r, v[i]);
  31.     }
  32.     fout << r << endl;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement