Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么答案总是错的!哪位高手帮帮忙啊!(附代码,)代码很简单,帮忙看看。#include <stdio.h> #include <math.h> int main() { int a1,b1,a2,b2,a3,b3,i; char c; while (scanf("%d/%d%c%d/%d",&b1,&a1,&c,&b2,&a2)!=EOF) { a3=a1*a2; if (c=='+') { b3=a2*b1+a1*b2; } if (c=='-') { b3=a2*b1-a1*b2; } for(i=2;i<=sqrt(a3)&&i<=sqrt(fabs(b3));) { if (a3%i==0&&b3%i==0) { a3=a3/i; b3=b3/i; i=2; } else i++; } if (b3==0) { printf("0\n"); } else if (b3%a3==0) { printf("%d\n",b3/a3); } else { printf("%d/%d\n",b3,a3); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator