#include int main(int argc, char *argv[]) { float a, b, Txy=0.0, Tx=0.0, Ty=0.0, Sx2=0.0, Sxy=0.0, height, weight, count=0.0; char filename[25]; FILE *fp, *fp2; /*ファイルが存在しない時*/ if ((fp = fopen(argv[1], "r")) == NULL){ printf("%s Not found...\n,argv[1]"); exit(1); } /*読み込み処理*/ printf("now reading...\n"); printf("----------------\n-----STATAS-----\n----------------\n"); while (fscanf(fp,"%f %f\n", &height, &weight) != EOF){ Tx = Tx + height; Ty = Ty + weight; Txy = Txy + ( height * weight ); Sx2 = Sx2 + ( height * height ); count = count + 1; printf("height = %f weight = %f\n", height, weight); printf("Tx = %f Ty = %f\n",Tx,Ty); printf("Txy = %f Sx2 = %f\n",Txy,Sx2); printf("-------- count = %f --------\n",count); } Sx2 = Sx2 / count; Sx2 = Sx2 - ( Tx * Tx ) / ( count * count ); Sxy = ( Txy / count ) - ( Tx * Ty ) / ( count * count ); a = Sxy / Sx2; b = Ty / count - a * ( Tx / count ); /*表示処理*/ printf("\a HIT!!\n a = %f\n b = %f\n",a,b); }