Code Box
-------------------------------------
/*Program to find H.C.F. of two numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num1,num2,remainder,dividend,divisor;
printf("\n---------------H.C.F. Calculator --------------------");
printf("\nEnter two numbers..");
printf("\nEnter first number: ");
scanf("%d",&num1);
printf("\nEnter second number: ");
scanf("%d",&num2);
if(num1>num2) //Checker for greater number
{
remainder=num1%num2;
dividend=num2;
}
else{
remainder=num2%num1;
dividend=num1;
}
//If remainder is zero
if(remainder==0)
{
printf("\nH.C.F. of %d & %d is : %d",num1,num2,dividend);
}
else
{
divisor=remainder;
while(remainder !=0)
{
remainder=dividend%divisor;
dividend=divisor;
divisor=remainder;
}
printf("\nH.C.F. of %d & %d is : %d",num1,num2,dividend);
}
printf("\n---------------H.C.F. Calculator --------------------");
getch();
}
No comments:
Post a Comment