個人相片
10030310
100資專0310 林宣含發表於2012年 03月 28日(三.) 16:51
 

/*
一仁  10  林宣含
file
*/
#include<stdlib.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
    int n,i;
    double a[60],b[60],c[60],D[60],X1[60],X2[60];

    FILE *in,*out;
    in=fopen("D:\\10030310\\in.txt","r");
    if(in!=NULL)
    {
      fscanf(in,"%d",&n);
   
     
      for(i=1;i<=n;i++)
      {
       fscanf(in,"%lf %lf %lf",&a[i],&b[i],&c[i]);
       D[i]=b[i]*b[i]-4*a[i]*c[i];
     
   
     
       if(D[i]<0)
       {
              printf("non");
       }
       else if(D[i]>=0)
          
       {
              X1[i]=(-b[i]+sqrt(D[i]))/(2*a[i]);
              X2[i]=(-b[i]-sqrt(D[i]))/(2*a[i]);
              printf("%.3lf,%.3lf\n",X1[i],X2[i]);
       }
       else
       printf("File Opening Failure\n");
       }
    }

    system("PAUSE");
    return 0;
}
/*
-1.000,-1.000
-0.500,-1.000
-0.667,-1.000
請按任意鍵繼續 . . .
*/  

個人相片
回應: 10030310
100資專0310 林宣含發表於2012年 03月 28日(三.) 16:57
 

/*
一仁  10  林宣含
file
*/
#include<stdlib.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
    int n,i;
    double a[60],b[60],c[60],D[60],X1[60],X2[60];

    FILE *in;
    in=fopen("D:\\10030310\\in.txt","r");
    if(in!=NULL)
    {
      fscanf(in,"%d",&n);
   
     
      for(i=1;i<=n;i++)
      {
       fscanf(in,"%lf %lf %lf",&a[i],&b[i],&c[i]);
       D[i]=b[i]*b[i]-4*a[i]*c[i];
     
   
     
       if(D[i]<0)
       {
              printf("non\n");
       }
       else if(D[i]>=0)
          
       {
              X1[i]=(-b[i]+sqrt(D[i]))/(2*a[i]);
              X2[i]=(-b[i]-sqrt(D[i]))/(2*a[i]);
              printf("%.3lf,%.3lf\n",X1[i],X2[i]);
       }
       else
       printf("File Opening Failure\n");
       }
    }

    system("PAUSE");
    return 0;
}
/*
-1.000,-1.000
-0.500,-1.000
-0.667,-1.000
請按任意鍵繼續 . . .
*/    
/*
non
non
-0.500,-1.000
-1.000,-1.000
-0.049,-12.351
請按任意鍵繼續 . . .
*/