請問一下這個程式的問題是什么,我是想輸入一個擁有十個數的陣列,然后就出現了一個問題,怎么解決這個問題。
#include<stdio.h>
#define NUMELS 10
double AVERAGE(int [],int);
int main()
{
int grades[NUMELS];
int i;
double average;
for(i=0;i<NUMELS;i++)
{
printf("please type in the number:\n");
scanf("%d",&grades[NUMELS]);
}
average=AVERAGE(grades,NUMELS);
printf("%f",average);
}
double AVERAGE(int grades[],int NUMELS)
{
int i;
double total=0.0;
for(i=0;i<NUMELS;i++)
{
total+=grades[i];
}
return(total/NUMELS);
}
uj5u.com熱心網友回復:
for(i=0;i<NUMELS;i++){
printf("please type in the number:\n");
scanf("%d",&grades[i]);
}
uj5u.com熱心網友回復:
double AVERAGE(int grades[],int NUMELS這一行老有問題說讓我在引數前面加逗號或者省略號什么意思啊
uj5u.com熱心網友回復:
double AVERAGE(int grades[],int NUMELS)第2個入參,與宏定義沖突了,換一下
uj5u.com熱心網友回復:
for(i=0;i<NUMELS;i++){
printf("please type in the number:\n");
scanf("%d",&grades[i]);
}
uj5u.com熱心網友回復:
#include <stdio.h>
#define N 10
double average(int [], int);
int main()
{
int grades[N];
int i;
double result;
for (i = 0; i < N; i++)
{
printf("please type in the number: ");
scanf("%d", &grades[i]);
}
result = average(grades, N);
printf("%f\n", result);
return 0;
}
double average(int grades[], int n)
{
int i;
double total = 0.0;
for (i = 0; i < n; i++)
{
total += grades[i];
}
return (total / n);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/67781.html
標籤:新手樂園
上一篇:VS Code問題20200510--(numeric_limits<char>::min)()無法使用
下一篇:cmd命令寫bat
