void main() { int a,b,i,v,lcm=1; printf("Enter two numbers"); scanf("%d %d",&a,&b); while(i<=(a*b)) { if( a%i==0 && b%i==0) { v= i*lcm; i++; } else i++; } printf("The lcm is %d",v); getch(); }
i
while
#include <stdio.h> int main() { int a,b,lcm; printf("Enter two numbers\n"); scanf("%d %d",&a,&b); lcm = a > b ? a : b; while(lcm <= (a*b) ) { if( lcm%a==0 && lcm%b==0) { break; } ++lcm; } printf("The lcm is %d\n",lcm); getchar(); return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)