C program to find the GCD by recursion.
In this tutorial we will learn how to write a c program to find the GCD and LCM of given numbers.GCD or HCF of two numbers is the greatest number which can be divided by both numbers.
In this output we will see, this program find the GCD of two numbers.
In the first we will enter two numbers and stored in variables num1 and num2.
The GCD stored in gcd variable.
In this tutorial we will learn how to write a c program to find the GCD and LCM of given numbers.GCD or HCF of two numbers is the greatest number which can be divided by both numbers.
LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.
C program code
#include<stdio.h>
#include<conio.h>
int GetGCD(int temp1,int temp2);
int main()
{
int num1,num2,gcd,lcm,x;
printf("\n ENTER TWO NUMBERS:\n ");
scanf("%d%d",&num1,&num2);
gcd=GetGCD(num1,num2);
lcm=(num1*num2)/gcd;
printf("\n GCD OF GIVEN NUMBER IS: %d\n",gcd);
printf("\n LCM OF GIVEN NUMBER IS: %d\n",lcm);
}
int GetGCD(int temp1,int temp2)
{
if(temp2!=0)
{
GetGCD(temp2,temp1%temp2);
}
else
{
return(temp1);
}
}
OUTPUT:
In this output we will see, this program find the GCD of two numbers.
In the first we will enter two numbers and stored in variables num1 and num2.
The GCD stored in gcd variable.
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment