Saturday, August 20, 2011

Program to find hcf and lcm of two numbers

//Program to find hcf and lcm of two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,a,b,h,l,r=1;
clrscr();
printf("Program to find hcf nd lcm of two numbers");
printf("Enter the two numbers greater then equal to 1: ");
scanf("%d%d",&m,&n);
if(m>=1&&n>=1)
{
if(m>=n)
{
a=m;
b=n;
}
else
{
a=n;
b=m;
}
while(r!=0)
{
 r=a%b;
 if(r!=0)
 {
  a=b;
  b=r;
 }
}
h=b;
l=(m*n)/h;
}
printf("hcf of two numbers is %d and lcm of two numbers is %d ",h,l);
getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More