当前位置:
首页 >
[YTU]_2498 (C++类实现最大数的输出)
发布时间:2025/4/16
30
豆豆
生活随笔
收集整理的这篇文章主要介绍了
[YTU]_2498 (C++类实现最大数的输出)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Description
输入n个数,找出最大的数并输出。
Input
输入n,并输入n个数。
Output
输出的最大的数,每个输出结果占一行。
Sample Input
10 1 2 3 4 5 6 7 8 9 10Sample Output
10#include <iostream> using namespace std; class Q { public:void set_value();int get_Max(); private:int n;int a[100]; }; int main() {Q b1;b1.set_value();cout<<b1.get_Max()<<endl;return 0; } void Q::set_value() {cin>>n;int i;for(i=0;i<n;i++){cin>>a[i];} } int Q::get_Max() {int i, max=a[0],m=0;for(i=1;i<n;i++){if(a[i]>=max)max=a[i];}return max; }总结
以上是生活随笔为你收集整理的[YTU]_2498 (C++类实现最大数的输出)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: [YTU]_2433( C++习题 对象
- 下一篇: [YTU]_2499( 处理成绩(c++