程序Segmentation fault的问题
像编写一个求n个数平均数的程序,但是测试的时候出现了Segmentation fault错误,不知道怎么改,求大神纠正,以下是程序,谢谢!!!程序代码:
#include <stdio.h> #include <math.h> int main(void) { int n, m, sum; int a[n]; double average; printf("Enter n: "); scanf("%d", &n); printf("Enter numbers: "); for(m = 0; m <= n; m++){ scanf("%d", &a[n]); sum+=a[m]; } average = sum / n; printf("average = %1.2lf\n", average); return 0; }