You are on page 1of 1

#include <iostream>

using namespace std;

int lcm_twono(int n1, int n2)


{
int max=(n1>n2)?n1:n2;

while(true)
{
if(max%n1==0&&max%n2==0)
{
return (max);
}
++max;
}

int lcm_a(int a[],int num)


{
int lcm=lcm_twono(a[0],a[1]);
for(int j=2;j<num;j++)
{
lcm=lcm_twono(lcm,a[j]);
}
return (lcm);
}

int main()
{
int a[20];
int i,n,num ;
cout<<"Enter the number of element work on: "<<endl;
cin>>n;

for(i=0;i<n;i++)
{
int p;
cout<<"Enter the number for a["<<i<<"] is ";
cin>>p;
}
num=sizeof(a)/sizeof(a[0]);
cout<<"lcm of array is ="<<lcm_a(a,num);

You might also like