Socialize

Breaking

Saturday, March 14, 2020

Write a program in c to print HCF of two numbers. Using while-loop

// Write a program to print HCF of two numbers. Using while-loop.//


hcf stand for highest comman factor

program :

#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b,i,h;
    printf("\n Enter the value of a= ");
    scanf("%d",&a);
    printf("\n Enter the value of b= ");
    scanf("%d",&b);
    if(a>b)
    {
        h=a;
    }
    else
    {
        h=b;
    }
    i=h;
    while(i>=1)
    {
        if(a%i==0 && b%i==0)
        {
            printf("\n HCF=%d",i);
            break;
        }
        i--;
      }
    getch();
}

output:


No comments:

Post a Comment