Skip to content

Commit

Permalink
Merge pull request #119 from jakansha2001/temp
Browse files Browse the repository at this point in the history
HCF of N Numbers
  • Loading branch information
akshitagupta15june authored May 26, 2021
2 parents 9ef6717 + d8e130a commit 1620b3b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Maths/HCFofNnumbers.java
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;
}
}

0 comments on commit 1620b3b

Please sign in to comment.