Saturday, 25 May 2013

0 A C - PROGRAM TO FIND THE GREATEST COMMON DIVISIOR (GCD) AND LEAST COMMON MULTIPLE (LCM)

The greatest common divisor (GCD), which is also known as the greatest common factor (GCF), of two or more integers is the largest integer that is a common divisor (factor) of all the given integers.
Least Common Multiple
The least common multiple (LCM), which is also known as the least common denominator (LCD) in fractions, of two or more integers is the smallest integer that is a common multiple (denominator) of all the given integers.

THE PROGRAM IS TO FIND GCD AND LCM :
#include<stdio.h>
#include<conio.h>
void main()
{
 int m,n,gcd,lcm,rem,p,q;
 printf("enter the no m and n \n");
 scanf("%d%d",&m,&n);
 p=m;
 q=n;
 while(n!=0)
 {
     rem=m%n;
     m=n;
     n=rem;
}
  gcd=m;
  printf("\n gcd of %d and %d is = %d\n",p,q,gcd);
  lcm=(p*q)/gcd;
  printf("\n lcm of %d and %d is = %d\n",p,q,lcm);
getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it to find GCD and LCM ...
Click HERE to download this file.

~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

No comments:

Post a Comment