zoukankan      html  css  js  c++  java
  • 输入若干个整数求出其最大值。

    输入若干个整数求出其最大值。

    源代码:

    1. #include <iostream>
    2. using namespace std;
    3. int Largest(int list[],int length)
    4. {
    5.    int i,max=list[0];
    6.    for(i=0;i<length;i++)
    7.    {
    8.       if (list[i]>max)
    9.          max=list[i];
    10.    }
    11.    return max;
    12. }
    13. void main()
    14. {
    15.    int max=0,N=-1,list[1000];
    16.    cout<<"请输入整数个数,范围为0到1000:";
    17.    cin>>N;
    18.    cout<<"please enter "<<N<<" inter:"<<endl;
    19.    for(int i=0;i<=N-1;i++)
    20.       cin>>list[i];
    21.    max=Largest(list,N);
    22.    cout<<"最大值为:"<<max<<endl;
    23. }

     

    第一组测试数据:从小到大:1 2 3 4 5 6 7 8 9 10

     

    第二组测试数据,从大到小:10 9 8 7 6 5 4 3 2 1

     

    第三组测试数据,小大小大。。。。。:1 10 9 2 8 3 7 4 6 5

     

    第四组测试数据,大小大小。。。。。:12 1 11 2 10 3 9 4 8 5 7 6

     

    第五组测试数据,有负数:-1 0 6 8 3 2

     

    第六组测试数据,有重复的数据:2 7 8 8 6 7

  • 相关阅读:
    ssh
    datetime
    网络-sdn(2)
    django-drf
    Vscode前段常用插件
    Vscode离线安装插件
    CSS 实现绘制各种三角形
    flex布局
    js实现全选和取消全选
    购物车用Ajax向后台传参
  • 原文地址:https://www.cnblogs.com/diyunfei/p/5301947.html
Copyright © 2011-2022 走看看