分别编写求数组a中最大值max(int a[],int n)和最小值min(int a[],int n)的函数,其中n是数组a的大小
编写主函数main()完成:输入n个整数给数组a;分别调用max()和min()函数求出a中的最大值和最小值,并返回给main()函数输出...
编写主函数main()完成:
输入n个整数给数组a;
分别调用max()和min()函数求出a中的最大值和最小值,并返回给main()函数输出。
最好把做好的程序发至fengyunn456@163.com 展开
输入n个整数给数组a;
分别调用max()和min()函数求出a中的最大值和最小值,并返回给main()函数输出。
最好把做好的程序发至fengyunn456@163.com 展开
3个回答
展开全部
#include <iostream>
using namespace std;
int max(int a[], int n)
{
int tmp = a[0];
for (int i = 0; i!=n; ++i)
if (tmp < a[i])
tmp = a[i];
return tmp;
}
int min(int a[], int n)
{
int tmp = a[0];
for (int i = 0; i!=n; ++i)
if (tmp > a[i])
tmp = a[i];
return tmp;
}
int main()
{
int *num = 0, len=0;
cout << "请输入数的个数:";
cin >> len;
num = new int[len];
cout << "请输入所有的数:";
for (int i = 0; i!=len; ++i)
cin >> num[i];
cout << "最大值为" << max(num, len) << endl;
cout << "最小值为" << min(num, len) << endl;
delete [] num;
return 0;
}
using namespace std;
int max(int a[], int n)
{
int tmp = a[0];
for (int i = 0; i!=n; ++i)
if (tmp < a[i])
tmp = a[i];
return tmp;
}
int min(int a[], int n)
{
int tmp = a[0];
for (int i = 0; i!=n; ++i)
if (tmp > a[i])
tmp = a[i];
return tmp;
}
int main()
{
int *num = 0, len=0;
cout << "请输入数的个数:";
cin >> len;
num = new int[len];
cout << "请输入所有的数:";
for (int i = 0; i!=len; ++i)
cin >> num[i];
cout << "最大值为" << max(num, len) << endl;
cout << "最小值为" << min(num, len) << endl;
delete [] num;
return 0;
}
展开全部
#include<iostream>
using namespace std;
const int SIZE = 10;
int max(int* a, int size);
int min(int* a, int size);
int
main(){
int* a = new int [SIZE];
int Num = 0;
int MAX = 0;
int MIN = 0;
cout<<"Plz input the elements:";
for(int i = 0; cin>>a[i]; i++){
Num++;
}
MAX = max(a, Num);
MIN = min(a, Num);
cout<<"The max number in the array is: "<<MAX<<endl;
cout<<"The min number in the array is: "<<MIN<<endl;
delete [] a;
system("pause");
return 0;
}
int
max(int* a, int size){
int result = a[0];
for(int i = 1; i < size; i++){
if(result < a[i]){
result = a[i];
}
}
return result;
}
int
min(int* a, int size){
int result = a[0];
for(int i = 1; i < size; i++){
if(result > a[i]){
result = a[i];
}
}
return result;
}
using namespace std;
const int SIZE = 10;
int max(int* a, int size);
int min(int* a, int size);
int
main(){
int* a = new int [SIZE];
int Num = 0;
int MAX = 0;
int MIN = 0;
cout<<"Plz input the elements:";
for(int i = 0; cin>>a[i]; i++){
Num++;
}
MAX = max(a, Num);
MIN = min(a, Num);
cout<<"The max number in the array is: "<<MAX<<endl;
cout<<"The min number in the array is: "<<MIN<<endl;
delete [] a;
system("pause");
return 0;
}
int
max(int* a, int size){
int result = a[0];
for(int i = 1; i < size; i++){
if(result < a[i]){
result = a[i];
}
}
return result;
}
int
min(int* a, int size){
int result = a[0];
for(int i = 1; i < size; i++){
if(result > a[i]){
result = a[i];
}
}
return result;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给100分,帮你做。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询