杭电2028

[复制链接]
查看11 | 回复0 | 2010-4-22 11:54:41 | 显示全部楼层 |阅读模式
//这个行,你试一下,是用栈写的,这是求公倍数和公约数的,有问题的话可以给我发个消息,#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"); }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行