Sunday, December 15, 2019

Write a program to find gcd of two numbers.

About:
The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder).
For example:81 and 153
The gcd(81,153)=9.

Program:
#include<stdio.h>
void main()
{
int n1,n2,gcd;
printf("Enter any two no:");
scanf("%d%d",&n1,&n2);
for(int i=1;i<=n1&&i<=n2;++i){
if(n1%i==0&&n2%i==0)
gcd=i;
}
printf("The gcd of %d and %d=%d",n1,n2,gcd);
}

No comments:

Post a Comment

Write a program to find gcd of two numbers using recursion.

About:  The process in which a function calls itself is called recursion and the corresponding function is called as recursive function. ...