zoukankan      html  css  js  c++  java
  • 通过函数求一组数组中最大最小的函数

    一、代码

     1 #include <iostream>
     2 using namespace std;
     3 //求整形数组中最大的元素
     4 int imax(int array[],int count)
     5 {
     6     int temp=array[0];
     7     for (int i=0;i<count;i++)
     8     {
     9         if(temp<=array[i])
    10             temp=array[i];
    11     }
    12     cout<<"最大的数为:"<<temp<<endl;
    13     return 0;
    14 
    15 }
    16 //求整形数组中最小的元素
    17 int imin(int array[],int count)
    18 {
    19     int temp=array[0];
    20     for (int i=0;i<count;i++)
    21     {
    22         if(temp>=array[i])
    23             temp=array[i];
    24     }
    25     cout<<"最小的数为:"<<temp<<endl;
    26     return 0;
    27 }
    28 //主函数
    29 void main()
    30 {
    31     cout<<"请输入数字的个数:"<<endl;
    32     int MaxSize=0;
    33     cin>>MaxSize;
    34     int *Array=new int[MaxSize];
    35     cout<<"请输入"<<MaxSize<<"个数字:"<<endl;
    36     for (int i=0;i<MaxSize;i++)
    37     {
    38         cin>>Array[i];
    39     } 
    40     imax(Array,MaxSize);
    41     imin(Array,MaxSize);
    42 }

    二、运行

  • 相关阅读:
    洛谷 P4001 [ICPC-Beijing 2006]狼抓兔子
    杂题20201201
    杂题20210103
    杂题20201010
    杂题20200928
    ACL1 Contest 1 简要题解
    杂题20200906
    杂题20200623
    USACO2020DEC Gold/Platinum 解题报告
    CSP-S2020游记
  • 原文地址:https://www.cnblogs.com/f59130/p/3329242.html
Copyright © 2011-2022 走看看