c++编程 求助!!!大神

2025-01-01 01:27:12
推荐回答(3个)
回答1:

#include "stdafx.h"
#include
using namespace std;
const int N=50;

double average(int score[], int number)
{
double s = 0.0;
for (int i = 0; i < number; ++i)
{
s += score[i];
}
return s / number;
}
int main()
{
int score[N];
double ave;
int n = 0;
cout << "输入成绩" << endl;
for (int i = 0; i < N; ++i)
cin >> score[i];
ave = average(score, N);
cout << "平均成绩为" << ave << endl;
int max = score[0];
n = 0;
for (int i = 1; i < N; ++i)
{
if (max < score[i])
max = score[i];
if (score[i] > ave)
++n;
}
cout << "max=" << max << endl;
cout << "超出平均分的人数为" << n << endl;
int min = score[0];
for (int i = 1; i < N; ++i)
{
if (min>score[i])
min = score[i];
if (score[i] < ave)
++n;
}
cout << "min=" << min << endl;
cout << "低于平均分的人数为" << n << endl;
return 0;
}

回答2:

#include 
#include 
using namespace std;
#define N 50
double average(int score[], int number)
{
int i;
double sum = 0.0;
for( i=0;i < number; i++)
{
sum += (double)score[i];
}
return sum/number;
}
int main(int argc, char *argv[])
{
srand((unsigned)time(0)); 
int ran_num,score[N];
for(int i=0;i  {
ran_num=rand()%100+1; 
score[i] = ran_num;
cout< }
cout< int max =score[0], min = score[0];
for( i=0;i < N; i++)
{
if(max < score[i])
max = score[i];
if(min > score[i])
min = score[i];
}
int hig =0,low = 0;
double avg = average(score, N);
for( i=0;i < N; i++)
{
if(avg < (double)score[i])
hig++;
if(avg > (double)score[i])
low++;
}
cout<<"max:"< cout<<"min:"< cout<<"avg:"< cout<<"hig:"< cout<<"low:"< return 0;
}

回答3:

b
double average(int score[], int number)

{
int sum = 0;

for(int i = 0; i < score.Length(); i++) //这里用number也可以

{
sum+= score[i];

}
return (double) sum/score.Length();
}

c
void main()
{
int highest = 0;
int lowest = 100;
int higherThan = 0;
int lowerThan = 0;

double myAverage = average(score, number);

for(int i = 0; i < score.Length(); i++)

{
if(score[i] > highest) highest = score;
if(score[i] < lowest) lowest = score;

if(score[i] > myAverage) higherThan++;

else lowerThan++;

}

}