c++ programme for finding the hcf of 2 inputted numbers
Answers
Answered by
0
Answer:
#include <iostream>
using namespace std;
int main() {
int i, num1, num2, min, hcf=1;
// Take two numbers from user
cout << "Enter two numbers : ";
cin >> num1 >> num2;
// Find minimum between two numbers
min = num1;
if(num2 < num1) {
min = num2;
}
for(i = 1; i <= min; i++) {
if((num1 % i) == 0 && (num2 % i) == 0) {
hcf = i;
}
}
cout << endl << "HCF of " << num1 << " and " << num2 << " : " << hcf;
return 0;
}
Similar questions
World Languages,
2 months ago
Math,
2 months ago
Social Sciences,
4 months ago
Science,
10 months ago
Math,
10 months ago