-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHcfofNumbers.c
48 lines (40 loc) · 874 Bytes
/
HcfofNumbers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
int main()
{
int num1, num2, hcf;
printf("Enter the two numbers : ");
scanf("%d", &num1);
scanf("%d", &num2);
if (num1 < 0)
{
num1 = num1 * (-1);
}
if (num2 < 0)
{
num2 = num2 * (-1);
}
if (num1 == 0 && num2 == 0)
{
printf("The HCF of the two given number is undefined\n");
}
else if (num1 == 0 && num2 != 0)
{
printf("The HCF of the two given number is %d\n", num2);
}
else if (num1 != 0 && num2 == 0)
{
printf("The HCF of the two given number is %d\n", num1);
}
else
{
for (int i = 1; i <= num1; i++)
{
if (num1 % i == 0 && num2 % i == 0)
{
hcf = i;
}
}
printf("The HCF of the two given number is : %d\n", hcf);
return 0;
}
}