#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { FILE *fptr; int n,i; double a[60],b[60],c[60],d[60],x1[60],x2[60]; fptr=fopen("E:\\10032326\\in.txt","r"); if(fptr!=NULL) { fscanf(fptr,"%d",&n); for(i=1;i<=n;i++) { fscanf(fptr,"%lf %lf %lf",&a[i],&b[i],&c[i]); d[i]=b[i]*b[i]-4*a[i]*c[i]; } for(i=1;i<=n;i++) { if(d[i]>=0) { x1[i]=(-b[i]+sqrt(d[i]))/(2*a[i]); x2[i]=(-b[i]-sqrt(d[i]))/(2*a[i]); fclose(fptr); printf("%.3lf,%.3lf\n",x1[i],x2[i]); } else printf("none\n"); } } else printf("File Opening Failure\n"); system("PAUSE"); return 0; }
|