LCM Problem: Gettign partially correct answer

I am not scored full for the LCM problem.
Can you please tell me what is wrong in my code.

Problem:
https://online.codingblocks.com/app/player/276028/content/265899/10075/code-challenge

My solution:
#######include
using namespace std;

int main(){
int n1, n2;
cin>>n1>>n2;

int div = 1;
int fact = 1;

int ans;

if(n1<=n2){
	while(div<=n1){
		if(n1%div == 0 && n2%div == 0){
			fact = fact*div;
		}
		div++;
	}
}
else{
	while(div<=n2){
		if(n1%div == 0 && n2%div == 0){
			fact = fact*div;
		}
		div++;
	}
}

ans = (n1*n2)/fact;

cout<<ans;
return 0;

}

hi @haardpatel07 try 4 and 8

Yes, it is giving false answer for this input. Any solution for this ?

hi @haardpatel07 lcm = a*b/gcd(a,b) just use this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.