我不明白程序是如何通过运行的。。。各种错误。。。
#include <iostream>
//#include <stdlib.h> 这就没有用233???
using namespace std;
/* 基础求最大值
int main()
{
int max(int x,int y);
int a,b,c;
cin>>a>>b;
c=max(a,b);
cout<<"max="<<c<<endl;
system("pause");
return 0;
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}
*/
// C++起航篇 单元巩固 第一次编译
//#include <iostream>
//using namespace std;
///**
// *函数功能:返回a和b的最大值
// *a和b是两个整数
// */
//int getMax(int a, int b)
//{
// return if(a > b)a =b;
//}
//
///**
// * 函数功能:返回数组中的最大值
// * arr:整型数组
// * count:数组长度
// * 该函数是对上面函数的重载
// */
//int getMax(numArr[i],count)
//{
// //定义一个变量并获取数组的第一个元素
// maxNum=numArr[0];
// for(int i = 1; i < count; i++)
// {
// //比较变量与下一个元素的大小
// if(maxNum<numArr[i])
// {
// //如果数组中的元素比maxNum大,则获取数组中的值
// maxNum=numArr[i];
// }
// }
// return maxNum;
//}
//
//int main(void)
//{
// //定义int数组并初始化
// int numArr[3] = {3, 8, 6};
//
// //自动调用int getMax(int a, int b)
// cout << getMax() << endl;
//
// //自动调用返回数组中最大值的函数返回数组中的最大值
// cout << getMax(numArr[i],count) << endl;
// return 0;
//}
//end;
//第一次编译单元巩固
//#include <iostream>
//using namespace std;
///**
// *函数功能:返回a和b的最大值
// *a和b是两个整数
// */
//int getMax(int a, int b)
//{
// //int x=a;
// //int y=b;
// //if(x > y) x =y;
// if(a>b)a=b;
// return a;
//}
//
///**
// * 函数功能:返回数组中的最大值
// * arr:整型数组
// * count:数组长度
// * 该函数是对上面函数的重载
// */
//int getMax(int numArr[],int count)
//{
// //定义一个变量并获取数组的第一个元素
// int maxNum=numArr[0];
// for(int i = 1; i < count; i++)
// {
// //比较变量与下一个元素的大小
// if(maxNum<numArr[i])
// {
// //如果数组中的元素比maxNum大,则获取数组中的值
// maxNum=numArr[i];
// }
// }
// return maxNum;
//}
//
//int main(void)
//{
// //定义int数组并初始化
// int numArr[3] = {3, 8, 6};
//
// //自动调用int getMax(int a, int b)
// //cout << getMax() << endl;
//
// //自动调用返回数组中最大值的函数返回数组中的最大值
// cout << getMax(numArr[3],3) << endl;
// system("pause");
// return 0;
//}
#include <iostream>
using namespace std;
/**
*函数功能:返回a和b的最大值
*a和b是两个整数
*/
int getMax(int a, int b)
{
if(a > b)a=b;
return a;
}
/**
* 函数功能:返回数组中的最大值
* arr:整型数组
* count:数组长度
* 该函数是对上面函数的重载
*/
int getMax(int *arr,int count)
{
//定义一个变量并获取数组的第一个元素
int maxNum=arr[0];
for(int i = 1; i < count; i++)
{
//比较变量与下一个元素的大小
if(maxNum<arr[i])
{
//如果数组中的元素比maxNum大,则获取数组中的值
maxNum=arr[i];
}
}
return maxNum;
}
int main(void)
{
//定义int数组并初始化
int numArr[3] = {3, 8, 6};
//自动调用int getMax(int a, int b)
cout << getMax(6,6) << endl;
//自动调用返回数组中最大值的函数返回数组中的最大值
cout << getMax(numArr,3)<< endl;
system("pause");
return 0;
}我不明白
int getMax(int a,int b)
{
return (a>b)? a:b;
}
这里改如何理解
并且
用
int getMax( int *arr,int count)
{
}
是如何对int getMax(int a, int b)
进行重载的。
求解答
(这其实是三个问题,因为每天提问有限额,所以。。。)