#include<iostream>
using namespace std;
int i = 0;
double score[16];
double sum;
double ave;
int min()//求最小值
{
double temp = score[0];
for (int count = 1; count < 16; count++)
{
if (score[i] < temp)
{
temp = score[i];
}
}
return temp;
}
double average()//求平均值
{
double sum = 0;
for (int i=0; i < 16; i++)
{
sum += score[i];
}
ave = sum / 16;
return ave;
}
int main()
{
cout << "請輸入第一個學生的4門成績:" << endl;
for (i = 0; i < 4; i++)
cin >> score[i];
cout << "請輸入第二個學生的4門成績" << endl;
for (i = 4; i < 8; i++)
cin >> score[i];
cout << "請輸入第三個學生的4門成績:" << endl;
for (i = 8; i < 12; i++)
cin >> score[i];
cout << "請輸入第四個學生的4門成績:" << endl;
for (i = 12; i < 16; i++)
cin >> score[i];
cout << "平均分為:" << average() << endl;
cout << "最低分為:" << min() << endl;
system("pause");
return 0;
}
16個成績求平均和最小值。
事實是平均值已經OK,但是求最小值的函數可能有問題,各位眼尖的幫我瞅瞅哪兒有錯,謝過各位!
if (score[i] < temp)
{
temp = score[i];
}
應該是:
if (score[count ] < temp)
{
temp = score[count ];
}