-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp-6-24.c
More file actions
42 lines (35 loc) · 815 Bytes
/
exp-6-24.c
File metadata and controls
42 lines (35 loc) · 815 Bytes
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
/*************************************************************************
> File Name: exp-6-24.c
> Author: xiaoxiaoh
> Mail: xiaoxxhao@gmail.com
> Created Time: Tue Jul 11 09:52:44 2017
************************************************************************/
/*
* Write a C program to find HCF (GCD) of two numbers. *
*
* Example
*
* Input
* Input first number: 12
* Input second number: 30
*
* Output
* HCF of 12 and 30: 6
*
*/
#include <stdio.h>
int main()
{
int i, num1, num2, min, hcf=1;
//Read two numbers from user
printf("Enter two numbers one by one: ");
scanf("%d%d", &num1, &num2);
min = (num1 < num2)? num1:num2;
for(i=1; i<=min; i++)
{
if((num1%i == 0) && (num2%i == 0))
hcf = i;
}
printf("HCF of %d and %d is %d\n", num1, num2, hcf);
return 0;
}