//这个行,你试一下,是用栈写的,这是求公倍数和公约数的,有问题的话可以给我发个消息,#include#include#define maxsize 10typedef struct stack{ int a[maxsize]; int top;}Stack;int gys(int x,int y){ int z,j; z=x>y?y:x; for (j=z;j>=1;j--)if (x%j==0&&y%j==0){ return j; break;}}int gbs(int x,int y){ int z,j; z=x>y?x:y; for (j=z;;j++)if (j%x==0&&j%y==0){ return j; break;}}void main(){ Stack *p; int a,b,t,k,m; printf("please input the number (stop by 0):"); p=(Stack*)malloc(sizeof(Stack)); p->top=-1; scanf("%d",&p->a[0]);p->top++; while (p->a[p->top]!=0) {p->top++;scanf("%d",&p->a[p->top]); } p->top--; if (p->top!=-1) {m=a=p->a[p->top--];while (p->top+1){ b=p->a[p->top--]; t=a;k=m; a=gbs(t,b); m=gys(k,b);}printf("The min gong bei shu is %d\nThe max gong yue shu is %d\n",a,m); } elseprintf("error\n"); } |