Advertisement
GrandtherAzaMarks

Mega GCD

May 27th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <cmath>
  3. #include <vector>
  4. int gcd(int a, int b) {
  5.     while (a != 0 && b != 0)
  6.         if (a > b) a %= b;
  7.         else b %= a;
  8.         return a + b;
  9. }
  10. int main()
  11. {
  12.     int n = 0;
  13.     int a = 0, b = 0;
  14.     scanf_s("%d%d", &n, &b);
  15.     for (int i = 1; i < n; i++)
  16.     {
  17.         scanf_s("%d", &a);
  18.         b = gcd(a, b);
  19.     }
  20.     printf("%d", b);
  21.     system("pause");
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement