如果此问题对您有帮助,请投票。 :)函数'sum'的隐式声明在C99中无效
我一直在寻找一个解决方案,但没有找到任何帮助。 我收到错误: - 隐式声明的函数'sum'在C99中无效 - 函数'average'的隐式声明在C99中无效 - '平均'的冲突类型 有没有人遇到过?我试图在Xcode中编译它。
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool
{
int wholeNumbers[5] = {2,3,5,7,9};
int theSum = sum (wholeNumbers, 5);
printf ("The sum is: %i ", theSum);
float fractionalNumbers[3] = {16.9, 7.86, 3.4};
float theAverage = average (fractionalNumbers, 3);
printf ("and the average is: %f \n", theAverage);
}
return 0;
}
int sum (int values[], int count)
{
int i;
int total = 0;
for (i = 0; i < count; i++) {
// add each value in the array to the total.
total = total + values[i];
}
return total;
}
float average (float values[], int count)
{
int i;
float total = 0.0;
for (i = 0; i < count; i++) {
// add each value in the array to the total.
total = total + values[i];
}
// calculate the average.
float average = (total/count);
return average;
}
检查这个答案,为我工作就像一个魅力! https://stackoverflow.com/a/46221365/3063226 – Heitor