Merge pull request #19 from shivhek25/master

Modified it.
This commit is contained in:
Chetan Kaushik 2017-06-02 11:45:30 +05:30 committed by GitHub
commit 163192b3f1

View File

@ -1,20 +1,23 @@
//This program aims at calculating the GCD of n numbers by division method
#include <iostream> #include <iostream>
using namepsace std; using namepsace std;
int main() int main()
{ {
cout <<"Enter value of n:"<<endl;
cin >> n; cin >> n;
int a[n]; int a[n];
int i,j,gcd; int i,j,gcd;
cout << "Enter the n numbers:" << endl;
for(i=0;i<n;i++) for(i=0;i<n;i++)
cin >> a[i]; cin >> a[i];
j=1; j=1; //to access all elements of the array starting from 1
gcd=a[0]; gcd=a[0];
while(j<n) while(j<n)
{ {
if(a[j]%gcd==0) if(a[j]%gcd==0) //value of gcd is as needed so far
j++; j++; //so we check for next element
else else
gcd=a[j]%gcd; gcd=a[j]%gcd; //calculating GCD by division method
} }
cout << "GCD of entered n numbers:" << gcd; cout << "GCD of entered n numbers:" << gcd;
} }