8. Write a program to calculate HCF of Two given number.

on
#include<iostream>
using namespace std;

int main()
{
    int i, num1, num2, min, hcf=1;
    cout<<"Enter any two numbers to find HCF: ";
    cin>>num1>>num2;

    // Find minimum between two numbers
    min = (num1<num2) ? num1 : num2;
    for(i=1; i<=min; i++)
    {
        if(num1%i==0 && num2%i==0)
        {
            hcf = i;
        }
    }

    cout<<"HCF = "<<hcf;
    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s