# finding LCM

 chinesh doshi · November 20, 2015 #includeint main(){    int a,b,i,lcm=1;    printf("enter the 1 numbers \n");    scanf("%d",&a);    printf("enter the 2 numbers \n");    scanf("%d",&b);    for(i=2;i<=a;i++){        if((a%i)==0&&(b%i)==0){            a= a/i;            b= b/i;            lcm = lcm*i;        }        else if((a%i)==0&&(b%i)!=0){            a =a/i;            lcm = lcm*i;        }        else if((a%i)==0&&(b%i)!=0){            b = b/i ;            lcm = lcm*i;        }        else{            a =a;            b=b;        }    }    printf("%d",lcm);    return 0 ;}whats the problem here ??

## Replies

 Vaggelis Dou · November 21, 2015 does it run anyways or not? chinesh doshi · December 25, 2015 no Linguist Llama · December 27, 2015 "whats the problem here ?? "I don't know. You haven't told us.If your problem is calculating the lowest common multiple of two integers, then this code is functionally incompatible; it does too much. When a % i == 0 && b % i == 0 you have found the lowest common multiple. You should break out of the loop at this point... but instead your loop continues. Why? Do you hope to find an even lower multiple by incrementing i?Why do you think you need to divide each number by each of its factors to find the lowest common multiple?
• 1

## C

124,312 followers