YTU 2498 C++类实现最大数的输出

版权声明:转载请附上原文链接哟! https://blog.csdn.net/weixin_44170305/article/details/90049745

风华是一指流砂,苍老是一段年华。

题目描述

输入n个数,找出最大的数并输出。

输入

输入n,并输入n个数。

输出

输出的最大的数,每个输出结果占一行。

样例输入

copy

10
1 2 3 4 5 6 7 8 9 10

样例输出

10

提示

主函数未给出,需要自己加上。

class Q
{

public:

   //此处声明需要的成员函数

private:

  int n;
  int a[100];

};

//下面定义成员函数

//用main()函数测试,完成输入输出

int main()

{

  Q b1;

  b1.set_value();

  cout<<b1.get_Max()<<endl;
  return 0;

}
 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
class Q
{
public:
   void set_value();
   int get_Max();
private:
  int n;
  int a[100];
};
//下面定义成员函数
void Q::set_value()
{
    int i;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
}
int Q::get_Max()
{
    int i,mx=a[0];
    for(i=1;i<n;i++)
        mx=max(a[i],mx);
        return mx;
}
//用main()函数测试,完成输入输出
int main()
{
  Q b1;
  b1.set_value();
  cout<<b1.get_Max()<<endl;
  return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44170305/article/details/90049745