-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from jakansha2001/temp
HCF of N Numbers
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.io.*; | ||
import java.util.Scanner; | ||
|
||
class Hcf | ||
{ | ||
public static void main(String arg[]) | ||
{ | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
System.out.println("HCF of how many numbers? (numbers<=10) - "); | ||
int N=sc.nextInt(); | ||
long input[]=new long[N]; | ||
System.out.println("Enter "+ N+" numbers"); | ||
for(int i=0;i<N;i++) | ||
{ | ||
input[i]=sc.nextLong(); | ||
|
||
} | ||
long result = input[0]; | ||
for(int i = 1; i < input.length; i++) | ||
{ | ||
result= hcf(result, input[i]); | ||
} | ||
System.out.println("HCF="+result); | ||
} | ||
} | ||
static long hcf(long a,long b) | ||
{ | ||
while (b > 0) | ||
{ | ||
long temp = b; | ||
b = a % b; | ||
a = temp; | ||
} | ||
return a; | ||
} | ||
} |