Advertisement
Guest User

Untitled

a guest
Oct 27th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int cmmdc(int a, int b)
  6. {
  7.     int t;
  8.     while (b != 0)
  9.     {
  10.         t = b;
  11.         b = a % b;
  12.         a = t;
  13.     }
  14.     return a;
  15. }
  16. int a[101];
  17.  
  18. int main()
  19. {
  20.     int n;
  21.     ifstream fin("cmmdc.in");
  22.     fin>>n;
  23.     for(int i=1; i<=n; i++)
  24.         fin>>a[i];
  25.  
  26.     int d=cmmdc(a[1],a[2]);
  27.     for(int i=3; i<=n; i++)
  28.         d=cmmdc(d,a[i]);
  29.  
  30.     ofstream fout("cmmdc.out");
  31.     fout<<d;
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement