TheAlgorithms-C-Plus-Plus/GCD_of_n_numbers.cpp

22 lines
311 B
C++
Raw Normal View History

2017-06-02 13:48:56 +08:00
#include <iostream>
using namepsace std;
int main()
{
2017-06-02 13:53:54 +08:00
cout <<"Enter value of n:"<<endl;
2017-06-02 13:48:56 +08:00
cin >> n;
int a[n];
int i,j,gcd;
for(i=0;i<n;i++)
cin >> a[i];
j=1;
gcd=a[0];
while(j<n)
{
if(a[j]%gcd==0)
j++;
else
gcd=a[j]%gcd;
}
cout << "GCD of entered n numbers:" << gcd;
}