Beta Coder

Learn code like Beta Coder.

Breaking

Friday, September 25, 2020

C Program to Find GCD or HCF of Two Numbers

Find GCD or HCF of Two Numbers

C PROGRAM TO FIND GCD OR HCF OF TWO NUMBERS
In this program we learn how to calculate GCD or HCF of two numbers by provided user using C.
C program to calculate GCD or HCF of two numbers
// FIND GCD OR HCF OF TWO NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
	int g, a, b, r;
	clrscr();
	printf("\n Enter two number : ");
	scanf("%d%d",&a,&b);
	do
	{
		r = a % b;
		a = b;
		b = r;
	}while(r != 0);
	printf("\n The G.C.D = %d",a);
	getch();
}
OUTPUT:
   Enter two numbers : 27 9
   The G.C.D = 9

No comments:

Post a Comment