My function has something wrong:
#include<iostream>
using namespace std ;
int max=1;
int lcm(int i){
if(max%i==0){
}
else
for (int b=2; b<=i ; b++){
max*=b;
max/=(b-1);
if(max%i==0){
break;
}
}
}
int main(){
int n;
cin>>n;
int i[n];
for(int j =0 ; j<n; j++){
cin>>i[j];
lcm(i[j]);
}
cout<<max+1;
}
This program gives me the lcm of several numbers.
I use global in python when I have this problem in my code whats function I should use in c++?
Or I should make my code better?