例4.6.txt
来自「清华大学谭浩强的C++教程」· 文本 代码 · 共 21 行
TXT
21 行
例4.6 编写一个程序,用来求两个整数或3个整数中的最大数。如果输入两个整数,程序就输出这两个整数中的最大数,如果输入3个整数,程序就输出这3个整数中的最大数。
#include <iostream>
using namespace std;
int main( )
{int max(int a,int b,int c); //函数声明
int max(int a,int b); //函数声明
int a=8,b=-12,c=27;
cout<<″max(a,b,c)=″<<max(a,b,c)<<endl; //输出3个整数中的最大者
cout<<″max(a,b)=″<<max(a,b)<<endl; //输出两个整数中的最大者
}
int max(int a,int b,int c) //此max函数的作用是求3个整数中的最大者
{if(b>a) a=b;
if(c>a) a=c;
return a;
}
int max(int a,int b) //此max函数的作用是求两个整数中的最大者
{if(a>b) return a;
else return b;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?