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