Saturday, November 5, 2011

LCM in C


#include<stdio.h>
int lcm(int a,int b)
  {
    int n;
    for(n=1;;n++)
    {
  if(n%a == 0 && n%b == 0)
   return n;
    }
  }

void main()
{
int a,b,c;
printf("Plese enter two numbers:");
scanf("%d %d",&a,&b);

c=lcm(a,b);
printf("LCM: %d",c);

}

0 comments:

Post a Comment

You are most welcome for making comments here. I will consider your view and will reply you soon.