LCM of two number in C-language

                              Method-1

#include<stdio.h>
int main()
{
    int a,b,i,lcm,max;
    printf("Enter first number\n");
    scanf("%d",&a);
    printf("Enter second number\n");
    scanf("%d",&b);
    max=a>b?a:b;
    lcm=max;
    for(i=1;i<=max;i++)
    {
        if(max%a==0&&max%b==0)
        {
            lcm=max;
            break;
        }
        max=lcm+max;
    }
    printf("LCM of %d and %d is=%d",a,b,lcm);
}
                          Method-2

#include<stdio.h>
int main()
{
int a,b,i;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);

 for(i=1;;i=i+1)
 {
  if(i%a==0&&i%b==0)
  {
    printf("LCM of %d and %d is=%d",a,b,i);
   break;
}
 }
}

OUTPUT
Enter first number
30
Enter second number
9
LCM of 30 and 9 is=90

Visit Homepage

Comments

Popular posts

Creative pattern of butterfly in C-language

Program to show present time and date in C-language

Introduction of C-language.

Program to cheque enter number is a perfect number or not using if else in C-language

Program to cheque four digits number is palindrome or not in C-language

Program to print the cube of a number in c-language

Simple Hello world program in c- language