Loading
View RSS Feed

prafic

How To Find LCM And GCD of Two Numbers?

Rate this Entry
/* Program to find LCM and GCD of the given two numbers - LCMGCD.C */
Code:
# include <stdio.h>
# include <conio.h>
void main()
{
int n1, n2, prod, gcd, lcm,m,i ;
clrscr() ;
printf("Enter the two numbers : ") ;
scanf("%d %d", &n1, &n2) ;
prod = n1 * n2 ;
if(n1>n2 )
         m=n2;
    else
         m=n1;

    for(i=m;i>=1;i--){
         if(n1%i==0 && n2%i==0){
             gcd = i ;
             break;
         }
    }

lcm = prod / gcd ;
printf("\nThe GCD is : %d", gcd) ;
printf("\n\nThe LCM is : %d", lcm);
getch() ;
}
OUTPUT

RUN 1 :
--------
Enter the two numbers : 10 8
The GCD is : 2
The LCM is : 40

Submit "How To Find LCM And GCD of Two Numbers?" to Digg Submit "How To Find LCM And GCD of Two Numbers?" to del.icio.us Submit "How To Find LCM And GCD of Two Numbers?" to StumbleUpon Submit "How To Find LCM And GCD of Two Numbers?" to Google

Updated 12-25-2011 at 02:24 PM by Harsh

Categories
C C++

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.