C语言编程题,输入N 个正整数(10 < Ν ≤20 )存入数组 a 中,输出 a 中的最大值?
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int N=1;
int num[20] = { 0 };
int max, min, sum=0;
float ava=0;
while (!(N > 10 && N <= 20))
{
cout << "请输入N的值:" << endl;
cin >> N;
}
cout << "请输入N个正整数,回车键结束!" << endl;
for (int i = 0; i < N; i++)
cin >> num[i];
max = num[0];
min = num[N - 1];
for (int i = 0; i < N; i++)
{
if (num[i] > max)
max = num[i];
if (num[i] < min)
min = num[i];
sum += num[i];
}
ava = (float)sum / N;
cout << "最大数:" << max << endl;
cout << "最小数:" << min << endl;
cout << "总数:" << sum << endl;
printf("平均数:%.2f", ava);
//cout << "平均数:" << ava << endl;
system("pause");
return 0;
}
#define N 20
void main() { int a[N],n,i,max,min; float av;
scanf("%d",&n);
if ( n>10 && n<=N ) {
for ( i=0;i<n;i++ ) scanf("%d",&a[i]);
max=min=av=a[0];
for ( i=1;i<n;i++ ) { av+=a[i]; if ( a[i]>max ) max=a[i]; else if ( a[i]<min ) min=a[i]; }
av/=n;
printf("最大值%d,最小值%d,平均值%.2f\n",max,min,av);
} else printf("输入值%d不在(10,20]区间。\n",n);
}