mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-09 21:47:07 +08:00
GCD of n numbers program
This commit is contained in:
20
GCD_of_n_numbers.cpp
Normal file
20
GCD_of_n_numbers.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
using namepsace std;
|
||||
int main()
|
||||
{
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user