Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Sunday, 8 September 2013

Program to Calculate and Print LCM & GCD of a Number | C Programming

Greatest Common Divisor (GCD) or Highest Common Factor (HCF) of two positive integers is the largest positive integer that divides both numbers without remainder. It is useful for reducing fractions to be in its lowest terms.

Lowest Common Multiple (LCM) of two integers is the smallest integer that is a multiple of both numbers.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,product;
clrscr();
printf("Enter two no.\n");
scanf("%d%d",&a,&b);
product=a*b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
printf("\nThe GCM is =%d",a);
printf("\nThe LCD is =%d",product);
getch();
}

Output:
Enter two number
4
6
The GCM is=2
The LCD is=24
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

0 comments :

Post a Comment

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine