在程序中镶嵌了个约分的循环,求解为什么不起作用
程序代码:
#include <stdio.h> main() { int a,b,e,f,h,l,m,n,o; char c,d,g; scanf("%d",&a); scanf("%c",&c); scanf("%d",&b); scanf(" %c ",&d); scanf("%d",&e); scanf("%c",&g); scanf("%d",&f); if(d=='+') {l=b*f; h=e*b+a*f; if(h==0) printf("%d/%d + %d/%d = 0\n",a,b,e,f); else {for(o=2;o<=5;o++) {if(a%o==0&&b%o==0) { h=h/o; l=l/o; }} printf("%d/%d + %d/%d = %d/%d\n",a,b,e,f,h,l); }} else if(d=='*') {l=a*e; h=b*f; if(l==0) {printf("%d/%d * %d/%d = 0\n",a,b,e,f); } else {for(o=2;o<=5;o++) {if(a%o==0&&b%o==0) { l=l/o; h=h/o; }} } printf("%d/%d * %d/%d = %d/%d\n",a,b,e,f,l,h); } else if(d=='-') { l=b*f; h=a*f-e*b; if(h==0) {printf("%d/%d - %d/%d = 0\n",a,b,e,f); } else {for(o=2;o<=5;o++) if(a%o==0&&b%o==0) { h=h/o; l=l/o; } printf("%d/%d - %d/%d = %d/%d\n",a,b,e,f,h,l); }} else if(d=='/') { l=a*f; h=b*e; if(l==0) printf("%d/%d / %d/%d = 0\n",a,b,e,f); else {for(o=2;o<=5;o++) if(a%o==0&&b%o==0) { h=h/o; l=l/o; } printf("%d/%d / %d/%d = %d/%d\n",a,b,e,f,l,h); } } }
[ 本帖最后由 gwz0012000 于 2011-3-16 20:32 编辑 ]