4个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int i,n = 10;
int a[10],min = 100,max = 0,sum = 0;
srand(unsigned(time(NULL)));
for(i = 0; i < 10; i++) {
a[i] = (unsigned)rand()%31 + 70;
if(a[i] > max) max = a[i];
else if(a[i] < min) min = a[i];
sum += a[i];
}
for(i = 0; i < n; i++) printf("%4d",a[i]);
printf("\n");
printf("最大值是 : %d\n",max);
printf("最小值是 : %d\n",min);
printf("平均值是 : %.2lf\n",(double)sum/n);
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a[10],i;
int minx,maxx,sum;
minx = 200;
maxx = 0;
sum = 0;
for(i=0;i<10;i++)
{
int x = rand() % 101;
if(x >= 30)
{
a[i]= x;
if(minx > a[i])
minx = a[i];
if(maxx < a[i])
maxx = a[i];
sum += a[i];
cout<<a[i]<<" ";
}
else
i--;
}
cout<<endl;
cout<<"max="<<maxx<<" "<<"min="<<minx<<" "<<"sum="<<sum<<" "<<"avg="<<sum/10<<endl;
return 0;
}
#include <cstdlib>
using namespace std;
int main()
{
int a[10],i;
int minx,maxx,sum;
minx = 200;
maxx = 0;
sum = 0;
for(i=0;i<10;i++)
{
int x = rand() % 101;
if(x >= 30)
{
a[i]= x;
if(minx > a[i])
minx = a[i];
if(maxx < a[i])
maxx = a[i];
sum += a[i];
cout<<a[i]<<" ";
}
else
i--;
}
cout<<endl;
cout<<"max="<<maxx<<" "<<"min="<<minx<<" "<<"sum="<<sum<<" "<<"avg="<<sum/10<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
int max=0;
int min=0;
void max_num(int* number,int first,int last)
{
if(first+1<last)
{
int i=(first+last)/2;
max_num(number,first,i);
max_num(number,i+1,last);
}
else if(first+1==last)
{
if(number[first]>number[last])
{
max=max>number[first]?max:number[first];
min=min<number[last]?min:number[last];
}
else if(number[first]<number[last])
{
max=max>number[last]?max:number[last];
min=min<number[first]?min:number[first];
}
}
else if(first==last)
{
max=max>number[first]?max:number[first];
min=min<number[last]?min:number[last];
}
};
int main()
{
int number[10];
int index=0;
int sum=0;
while(index<10)
{
int a=static_cast<int>(30+100*static_cast<long>(rand()))/(RAND_MAX+1);
number[index++]=a;
sum+=a;
}
int ave=sum/10;
max_num(number,0,9);
cout<<"The max is: "<<max<<endl
<<"The min is: "<<min<<endl
<<"The ave is: "<<ave<<endl;
return 0;
}
using namespace std;
int max=0;
int min=0;
void max_num(int* number,int first,int last)
{
if(first+1<last)
{
int i=(first+last)/2;
max_num(number,first,i);
max_num(number,i+1,last);
}
else if(first+1==last)
{
if(number[first]>number[last])
{
max=max>number[first]?max:number[first];
min=min<number[last]?min:number[last];
}
else if(number[first]<number[last])
{
max=max>number[last]?max:number[last];
min=min<number[first]?min:number[first];
}
}
else if(first==last)
{
max=max>number[first]?max:number[first];
min=min<number[last]?min:number[last];
}
};
int main()
{
int number[10];
int index=0;
int sum=0;
while(index<10)
{
int a=static_cast<int>(30+100*static_cast<long>(rand()))/(RAND_MAX+1);
number[index++]=a;
sum+=a;
}
int ave=sum/10;
max_num(number,0,9);
cout<<"The max is: "<<max<<endl
<<"The min is: "<<min<<endl
<<"The ave is: "<<ave<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询