#include <stdio.h> int f(int x,int y) // 通过求最大公约数的函数求出最大公约数是代码关键 { if(y==0) return x; else return f(y,x%y); } int main() { int a,b,x; while(scanf("%d%d",&a,&b)!=EOF) { if(a==b) printf("1\n"); else { x=f(a,b); a=a/x; b=b/x; printf("%d/%d\n",a,b); } } return 0; } |
Double click to view unformatted code.