我写出来了,可能有点乱,高手点评一下,谢谢 #include "stdio.h" #define N 10 main() { int CD(int a[],int n); int a[N] ,n, i,cd ,p,f; printf("input the amount:"); scanf("%d",&n); printf("you input %d number.\n",n); for (i=0;i<n;i++) { scanf("%d",&a[i]); } p=1; for(i=0;i<n;i++) { p=p*a[i]; } cd = CD(a,n); f=p/cd; if (cd!=1) printf("the common divisor is:%d\n",cd); else printf("No common divisor\n"); printf("the common multiple is:%d\n",f); }
CD(int arr[N],int n) { int i, m , k ,r,b,c,temp,temp2; if (arr[0]<arr[1]) { temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; } k=arr[0];m=arr[1]; while (m!=0) { r=k%m; k = m; m = r; } for (i=2;i<n;i++) { c= arr[i]; if (k<c) { temp2 = c; c = k; k = temp2; } while(c!=0) { b=k%c; k=c; c=b; } } return(k); }