C++类实现最大数的输出
Description
判断整数的大小,输入n个数,找出最大的数并输出。
Input
有多组测试实例,输入n,并输入n个数。
Output
输出的最大的数,每个输出结果占一行。
Sample Input
101 2 3 4 5 6 7 8 9 10
Sample Output
10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#include<iostream> #include<iomanip> using namespace std; class Q { public: void set_value(); int get_Max(); private: int n; int a[100]; }; void Q::set_value() { cin>>n; int i; for(i=0;i<n;i++) {cin>>a[i];} } int Q::get_Max() { int b,i; b=a[0]; for(i=0;i<n;i++) { if(b<a[i]) b=a[i]; } return b; } int main() { Q b1; b1.set_value(); cout<<b1.get_Max()<<endl; return 0; } |
This article is automatically posted by WP-AutoPost : WordPress自动采集发布插件
解决乱码问题,WP-AutoPost