正在加载图片...
2、参数个数上不同的重载函数 例143找出几个int型数中的最大者 #include <iostream.h> int max(int a, int b) int max(int a, int b, int c) a void main() cout<<max(12, 6)<<endl cout<<max(5, 9,-12)endl; j int max(int a, int b) return a>b?a: b:I int max(int a, int b, int c) int t if(a>=b)ta else tb if(c>t) t=c return t; j◼ 2、参数个数上不同的重载函数 ◼ 例14.3找出几个int型数中的最大者。 ◼ #include <iostream.h> ◼ int max(int a, int b); ◼ int max(int a, int b, int c); ◼ void main( ) ◼ { cout<<max(12,6)<<endl; ◼ cout<<max(5,9,-12)<<endl; } ◼ int max(int a, int b) ◼ { return a>b?a:b; } ◼ int max(int a,int b, int c) ◼ { int t; ◼ if (a>=b) t=a; ◼ else t=b; ◼ if (c>t) t=c; ◼ return t; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有