-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathGCC_nos.c
More file actions
52 lines (44 loc) · 736 Bytes
/
GCC_nos.c
File metadata and controls
52 lines (44 loc) · 736 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
43
44
45
46
47
48
49
50
51
52
Program:
#include <stdio.h>
int gcd();
int gcd(int m[],int l)
{
int i,pos,j,gcd2,min=m[0];
for(i=0;i<l;i++)
{
if(min>m[i])
{
min=m[i];pos=i;
}
}
for (j=0; j<l; j++)
{
if((m[j]%min==0))
{
gcd2=min;
}
else{
min--;j=0;
}
}
return gcd2;
}
void main()
{
int n,k;
printf("Enter the number of variables: ");
scanf("%d", &n);int a[n];
printf("\nEnter the elements: \n");
for(k=0;k<n;k++)
{
printf("A[%d]: ", (k+1));
scanf("%d", &a[k]);
}
printf("The GCD of the inputed numbers are: %d", gcd(a,n));
}
Output:
Enter the number of variables: 2
Enter the elements:
A[1]: 6
A[2]: 10
The GCD of the inputed numbers are: 5