64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stdlib.h>
using namespace std;
// function for get the max value,min value,and avage value of the random 100 number .
// By Evel
void main()
{
int how_many = 100;
int check[100];
int n=0;
cout << "Print "<< how_many << " random integers." << endl;
for (int i =0;i <how_many; ++i){
check[i]=rand();
cout << check[i] << '\t';
}
cout << endl;
//cout << check[0] <<endl;
int maxn = 0, min = check[0];
while(n<=how_many){
if(check[n]>maxn)
maxn=check[n];
else if(check[0]>check[n])
min=check[n];
n++;
}
cout << min << endl;
cout << maxn << endl;
}
#include <iostream>
#include <stdlib.h>
using namespace std;
// function for get the max value,min value,and avage value of the random 100 number .
// By Evel
void main()
{
const int how_many = 100; // 定义成const类型的
int check[how_many]; // 对数量引用,防止更改变量长度的时候while循环出问题
int n=0;
cout << "Print "<< how_many << " random integers." << endl;
for (int i =0;i <how_many; ++i){
check[i]=rand();
cout << check[i] << '\t';
}
cout << endl;
//cout << check[0] <<endl;
int maxn = 0, min = check[0];
while(n < how_many){ // =>循环条件订正。
if(check[n]>maxn)
maxn=check[n];
if(min > check[n]) // =>对最小值的判断条件订正
min=check[n];
n++;
}
cout << min << endl;
cout << maxn << endl;
}
n=0;
int maxn = min = check[n];
while(n<=how_many){
if(check[n]>maxn)
maxn=check[n];
else if(min>check[n])
min=check[n];
n++;
}
#include <iostream>
#include <stdlib.h>
using namespace std;
// function for get the max value,min value,and avage value of the random 100 number .
// By Evel
void main()
{
int how_many = 100;
int check[100];
int n=0;
cout << "Print "<< how_many << " random integers." << endl;
for (int i =0;i <how_many; ++i){
check[i]=rand();
cout << check[i] << '\t';
}
cout << endl;
//cout << check[0] <<endl;
int maxn = 0, min = check[0];
while(n < how_many){ // 1处!
if(check[n]>maxn)
maxn=check[n];
else if(min>check[n]) //2处
min=check[n];
n++;
}
cout << min << endl;
cout << maxn << endl;
}
#include <iostream>
#include <stdlib.h>
using namespace std;
// function for get the max value,min value,and avage value of the random 100 number .
// By Evel
void main()
{
int how_many = 100;
int check[100];
int n=0;
cout << "Print "<< how_many << " random integers." << endl;
for (int i =0;i <how_many; ++i){
check[i]=rand();
cout << check[i] << '\t';
}
cout << endl;
//cout << check[0] <<endl;
int maxn = 0, min = check[0];
while(n<=how_many){
if(check[n]>maxn)
maxn=check[n];
if(check[n]<min)
min=check[n];
n++;
}
cout << min << endl;
cout << maxn << endl;
}