그냥 인원 수랑 성적 입력하면 평균값 나오고 다음줄에 표준편차 나오는 코드야;

malloc은 합 저장변수 동적할당해서 수행하라해서 넣엇고...


#include <stdio.h>

#include <malloc.h>

#include <math.h>


int main()

{

    int i, kor, eng, math, num;

    int *sum;

double std_devi, average;

    

    FILE *input_fp = fopen("1132422.inp", "r") , *output_fp= fopen("1132422.out", "w");


    if( input_fp == NULL )

    {

    fprintf(stderr, "can't open %s\n", "1132422.inp" );

    }

    

    if( output_fp == NULL )

    {

    fprintf(stderr, "can't open %s\n", "1132422.out" );

    }


    // calloc(3, sizeof(int) )

    if( ( sum = (int *)malloc( sizeof(int)*3 )) == NULL )

    {

    fprintf(stderr, "memory allocation error %s\n", "sum" );

    }


fscanf(input_fp, "%d",&num);

    for(i=0;i<num;i++) 

    {

        fscanf(input_fp,"%d %d %d",&kor,&eng,&math);

*sum=kor+eng+math;

        average=(double)kor+eng+math/num;

        std_devi=(double)(kor*kor+eng*eng+math*math)/num-average*average;

        fprintf(output_fp,"%.1lf \n",average);

fprintf(output_fp,"%.1lf \n",sqrt(std_devi));

     }

    

    fclose( input_fp );

    fclose( output_fp );

    free( sum );

return 0;

}


존나 오류만 나네; 어디가 문제인지 알겠어? 총체적 난국인가?