×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Difference between Structure and Class - MAKAUT / WBUT MCA Slove Sum of its Individual Digit Until Single Digits - MAKAUT / WBUT MCA 2011
Find GCD and LCM of two positive integer - MAKAUT / WBUT MCA Slove - C Language
1875    Arnab De    16/11/2019

Write a program to find GCD and LCM of two positive integer values.

The Greatest Common Divisor(GCD) of two or more numbers is the largest non-zero positive number by which all the given numbers are divisible. For example, the GCD of 8 and 12 is 4.

softetechnologies

The Least Common Multiple (LCM) or Smallest Common Multiple of two or more numbers is the smallest non-zero positive integer that is divisible by all the given numbers. For example, LCM of 4 and 6 is 12.

The relation between GCD and LCM is

Product of numbers = GCD * LCM

#include <stdio.h>
int main()
{
 	int a,a1,b,b1,c,gcd,lcm;
 	printf("Enter First Number : ");
 	scanf("%d",&a);
	printf("Enter Second Number : ");
	scanf("%d",&b);
 	a1=a;
 	b1=b;
 	if(a > b)
 	{
 		c=a;
 		a=b;
 		b=c;
 	}
 	while(b%a!=0)
 	{
 		c=b%a;
 		b=a;
 		a=c;
 	}
 	gcd=a;
 	lcm=(a1*b1)/gcd;
 	printf("GCD is %d\n",gcd);
 	printf("LCM is %d\n",lcm);
}
softetechnologies

Output

========

Enter First Number : 25

Enter Second Number : 15

GCD is 5

LCM is 75

Difference between Structure and Class - MAKAUT / WBUT MCA Slove Sum of its Individual Digit Until Single Digits - MAKAUT / WBUT MCA 2011
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
All that man has to do is to take care of three things; good thought, good word, good deed.
Swami Vivekananda
85
80.83
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54128
25/06/2018     45121
01/01/2018     43673
28/06/2017     41209
02/08/2017     40224
01/08/2017     34268
06/07/2017     34071
15/05/2017     33309
11/09/2018     30326
14/07/2017     29835
softetechnologies