随笔 - 25,  文章 - 0,  评论 - 0,  阅读 - 2424

一.问题描述

利用数组和函数重载求5个数最大值(分别考虑整数、单精度、长整数的情况)。

二.编程思路

复制代码
#include <iostream>
using namespace std;
int Max(int a[])
{ 
    int max=a[0];
    for(int i=1; i<5; i++)
    {
        if(a[i]>max)
            max=a[i];
    }
    return max;
}
float Max(float b[])
{
    float max=b[0];
    for(int i=1; i<5; i++)
    {
        if(b[i]>max)
            max=b[i];
    }
    return max;
}
long Max(long c[])
{
    long max=c[0];
    for(int i=1; i<5; i++)
    {
        if(c[i]>max)
            max=c[i];
    }
    return max;
}
int main()
{
    int a[6];
    float b[6];
    long c[6];
    int m1;
    float m2;
    long m3;

    for(int i=0; i<5; i++)
        cin>>a[i];
    m1=Max(a);
    cout<<m1<<endl;

    for(int i=0; i<5; i++)
        cin>>b[i];
    m2=Max(b);
    cout<<m2<<endl;

    for(int i=0; i<5; i++)
        cin>>c[i];
    m3=Max(c);
    cout<<m3<<endl;
    return 0;
}
复制代码

 

posted on   标志蛋挞  阅读(158)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示