[ create a new paste ] login | about

Link: http://codepad.org/rzjpnYp5    [ raw code | output | fork ]

C, pasted on Jan 13:
#include <stdio.h>
#include <math.h>
#include <string.h>
typedef struct {
   char name[100];
   double y;
} point;
int main (void) {
  FILE * fp,*fp1;
  int num=0;
  char name [100];
  double score, weight,bunsan,hyoujyun,hensati;
  point a[100];
double sum=0.0,sum2=0.0,max=0.0,min=100;//sum総和sum22乗の総和
  fp = fopen ("data", "r");
  if (fp==NULL) {
    printf ("オープン失敗\n");
    return 0;
  }

 while (fscanf (fp, "%s%lf", name,
                 &score) == 2) {
					 
sum=sum+score;
sum2=score*score+sum2;
if(max<score)max=score;
if(min>score)min=score;
strcpy(a[num].name,name); 
a[num].y=score;
num++;
  }
 bunsan=sum2-(sum*sum/100)/100;
 hyoujyun=sqrt(bunsan);
 printf("max%f\nmin%f\n標準偏差%f\n平均%f",max,min,hyoujyun,sum/100);
  fclose (fp);


  fp1 = fopen ("output.txt", "w");
  num=0;
  while(num!=100){
	  hensati=(a[num].y-sum/100)/hyoujyun*10+50;
  fprintf (fp1, "%s\t%d\t%d\n",a[num].name,a[num].y,hensati);
  num++;
}
  fclose (fp1);

  return 0;
}


Output:
1
オープン失敗


Create a new paste based on this one


Comments: