डाउनलोड पी.डी.एफ. ई-बुक्स
C - Find Lcm And Gcd Of Two Numbers

विवरण :

कोई विवरण नहीं है |


सोर्स कोड :

#include<stdio.h>
 
 int main()
 {
 int num1,num2,temp1,temp2,gcd,lcm;
 
 printf("Enter two numeric values : ");
 scanf("%d%d",&num1,&num2);
 
 temp1=num1;
 temp2=num2;
 
 if(temp1 == 0)
 {
 gcd=temp2;
 }
 else if(temp2 == 0)
 {
 gcd=temp1;
 }
 else
 {
 while(temp2 != 0)
 {
 if(temp1 > temp2)
 {
 temp1=temp1-temp2;
 }
 else
 {
 temp2=temp2-temp1;
 }
 gcd=temp1;
 }
 }
 lcm=(num1*num2) / gcd;
 printf("LCM of %d and %d is %ld\n",num1,num2,lcm);
 printf("GCD of %d and %d is %d\n",num1,num2,gcd);

 return 0;
 }

आउटपुट :

Enter two numeric values : 55
5
LCM of 55 and 5 is 55
GCD of 55 and 5 is 5