C++——求3个数中最大的数(分别考虑整数、双精度数、长整数的情况),用函数模板来实现。

没注释的源代码

#include <iostream>

using namespace std;

template<typename T>

T max(T a,T b,T c)

{

if(b>a) a=b;

if(c>a) a=c;

return a;

}

int main()

{

int a,b,c;

double x,y,z;

long m,n,p;

cout<<"请输入三个整数:";

cin>>a>>b>>c;

cout<<"三个整数的最大值是:"<<max(a,b,c)<<endl;

cout<<"请输入三个浮点数:";

cin>>x>>y>>z;

cout<<"三个浮点数的最大值是:"<<max(x,y,z)<<endl;

cout<<"请输入三个长整数:";

cin>>m>>n>>p;

cout<<"三个长整数的最大值是:"<<max(m,n,p)<<endl;

return 0;

}

相关推荐
Nil2082 分钟前
leetcode 74搜索二维矩阵
算法·leetcode·矩阵
新知图书9 分钟前
第 14 章 后训练算法GRPO详解与实战
人工智能·算法
小白学大数据1 小时前
Codex 里的 GPT 6 Astra、GPT 5.6 Sol、Terra、Luna 怎么选
开发语言·gpt·microsoft
l1t2 小时前
DeepSeek 4.1总结的Tom Lane 谈塑造 Postgres 三十年历程的架构决策
开发语言·数据库·postgresql·架构
shirsl2 小时前
算法 Day1-数组 / 哈希 + 双指针
python·算法·哈希算法
djarmy8 小时前
MAIN.c(1): warning C318: can’t open file ‘STC8G.H’ 报错 解决 分析
c语言·开发语言·mongodb
HEJOO98 小时前
深入理解 Java volatile 关键字:原理、用法与常见误区
java·开发语言·spring
曹牧8 小时前
Java:no content to map due to end of input
java·开发语言
梦梦代码精9 小时前
《回收租赁系统技术选型避坑指南:业务闭环与二开自由度详解》
开发语言·低代码·docker·开源·代码规范
隔窗听雨眠9 小时前
记一次SQL Server数据库性能分析:从CPU100%到单配置修复的完整诊断
开发语言·数据库·php