定义内联函数max(),求两个整数中的最大值,然后再main()函数中进行调用的程序代码
答案:4 悬赏:40
解决时间 2021-04-07 07:58
- 提问者网友:雨之落き
- 2021-04-06 20:07
定义内联函数max(),求两个整数中的最大值,然后再main()函数中进行调用的程序代码
最佳答案
- 二级知识专家网友:陪伴是最长情的告白
- 2021-04-06 20:40
#include <stdio.h>
main()
{int max,a,b;
printf("请输入两个整数:");
scanf("%d%d",&a,&b);
max=max(a,b);
printf("最大值是:%d",max);}
main()
{int max,a,b;
printf("请输入两个整数:");
scanf("%d%d",&a,&b);
max=max(a,b);
printf("最大值是:%d",max);}
全部回答
- 1楼网友:懂得ㄋ、沉默
- 2021-04-07 00:24
// d.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
template<class T>
inline T max(T a,T b)
{
return (b>a)?b:a;//三目运算符如果(b>a)则返回b,否则返回a
}
int main()
{
cout <<"您要输出的大数是"<<max(3,4)<<endl;//您要比较的数凡在主函数调用中,比如输入的数为3,4.如果相比较浮点数则直接在主函数中原3,4.为之输入浮点数即可,注意输入数类型要相同。
return 0;
}
如有疑问请继续提问。
- 2楼网友:猖狂的痴情人
- 2021-04-06 22:51
int max(int m,int n){
return(m>=n?m:n); //若m>=n,返回m,反之返回n
}
#include<stdio.h>
main(){
void max(int m,int n)
int a,b;
scanf("%d%d",&a,&b);
printf("The result is:%d",max(a,b)); //调用函数结果打印之
return 0;
}
java代码如下:
import java.io.*;
class SEV {
public static void main(String[] args) throws IOException{
int max;
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("please input m:");
String r = input.readLine();
int m = Integer.parseInt(r);
System.out.print("please input n:");
String s = input.readLine();
int n = Integer.parseInt(s);
if(m>n) {max=m;}
else {max=n;}
System.out.println("max="+max);
}
}
- 3楼网友:绝望伪装
- 2021-04-06 21:13
#include <conio.h>
class a
{
public:
a(){};
bool IsNumberChar(char ch)
{
if(ch >= '0' && ch <='9')
return true;
else
return false;
}
};
void main()
{
a testa;
char ch = getch();
if(testa.IsNumberChar(ch))
printf("Input Is Number!");
else
printf("Input Not is Number!");
}
另外,团IDC网上有许多产品团购,便宜有口碑
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯