首页 > 试题广场 >

获取三个数中的最大值(三元表达式实现)

[编程题]获取三个数中的最大值(三元表达式实现)
  • 热度指数:25469 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
键盘录入三个整数 a、b、c,获取这三个整数中的最大值,并输出。(要求使用三元表达式实现)

输入描述:
输入任意三个整数


输出描述:
输出三个整数中的最大值
示例1

输入

100
200
300

输出

300
#include <iostream>
using namespace std;

int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    cout << ((a > b ? a : b) > c ? (a > b ? a : b) : c) << endl;

    return 0;
}

发表于 2021-11-11 16:22:06 回复(0)
#include <iostream>
using namespace std;

int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    cout<<max(a,max(b,c));
    

    return 0;
}

发表于 2023-01-27 14:08:43 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    int max = a>b?a:b;
    max=max>c?max:c;
    cout<<max;

    return 0;
}
发表于 2024-05-30 10:26:16 回复(1)
#include <iostream>
using namespace std;
int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
int fan=max(a,b);
    cout<<(max(fan,c));
    // write your code here......
    return 0;
}
发表于 2021-12-10 22:24:00 回复(1)
int main() {
    int a, b, c;
    cin >> a;cin >> b;cin >> c;
    cout <<((a>b?a:b)>c?(a>b?a:b):c);
    return 0;
}
发表于 2025-04-01 00:37:16 回复(0)
#include <stdio.h>
int max(int v,int m ,int n)
{
    if(v>m){
        if (v>n) return v;
        else return n;
    }
    else if (m>n){
        return m;
    }
    else return n;
}
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d",max(a,b,c));
}

发表于 2025-03-09 10:51:34 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    int max = 0;
    max = a>b? a:b;
    // max = max>c? max:c;
    cout << (max>c? max:c);
    return 0;
}
发表于 2025-01-07 11:39:23 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    int max_value = (a>=b?a>=c?a:c:b>=c?b:c);
    cout<<max_value<<endl;
    return 0;
}
发表于 2024-12-02 16:55:29 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    cout<<(a>b?(b>c?a:c>a?c:a):(a>c?b:c>b?c:b))<<endl;

    return 0;
}
发表于 2024-07-16 22:34:43 回复(0)
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int x=(a>b)?a:b;
    int y=(x>c)?x:c;
    printf("%d",y);
    return 0;
}
发表于 2024-07-07 20:34:22 回复(0)
#include <algorithm>
#include <iostream>

int main() {
    int a, b, c;

    // 输入三个整数
    std::cin >> a >> b >> c;

    // 使用三元表达式获取最大值
    int max_value = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
    int d = std::max(a, b);
    int e = std::max(d, c);
    // 输出结果
    std::cout<< e << std::endl;

    return 0;
}
发表于 2024-03-30 15:07:50 回复(0)
解法1:直接法
#include <iostream>
using namespace std;
 
int main() {
     
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
 
    int max1; //a、b中较大值
    int max2; //b、c中较大值
    int max;  //a、b、c中最大值
    max1 = (a>b)?a:b;
    max2 = (b>c)?b:c;
    max = (max1>max2)?max1:max2;
    cout<<max<<endl;
    return 0;
}

解法2:一行搞定
cout<< ((a>b?a:b)>c?(a>b?a:b):c);


发表于 2024-01-30 08:55:01 回复(1)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    int max=0;
    if(a>b)
        max = a;
    else    
        max = b;
    if(max<c)
        max = c;
       
    cout << max << endl;

    return 0;
}
发表于 2023-11-25 15:12:18 回复(0)
#include <iostream>
using namespace std;
#define mymax(a,b) ((a)>(b)? (a):(b))
int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    cout<<mymax(mymax(a,b),c)<<endl;
    // write your code here......
    return 0;
}
发表于 2023-11-13 17:29:46 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    cout << ((a > b) ? (a > c ? a : c) : (b > c ? b : c)) << endl;
    return 0;
}
发表于 2023-09-12 21:24:57 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    int max=a>b?a:b;
    max=max>c?max:c;
    cout<<max;

    return 0;
}
发表于 2023-08-16 15:11:35 回复(0)
#include <iostream>
using namespace std;

int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    cout<<((a>b?a:b)>c?(a>b?a:b):c);
    // write your code here......
    

    return 0;
}

发表于 2023-07-19 19:24:20 回复(0)
#include <iostream>
using namespace std;

int main() {
   
    int a, b, c;
    cin >> a >> b >> c;
    int d = (a > b) ? a : b;
    cout << ((d > c) ? d :c) << endl;

    return 0;
}
发表于 2023-06-15 19:56:47 回复(0)
#include <iostream>
using namespace std;

int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    cout << (a>b?a>c?a:c:b>c?b:c);

    return 0;
}

发表于 2023-06-06 09:43:25 回复(0)
#include <iostream>
using namespace std;

int main() {
    
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    // write your code here......
    cout<<(a>(b>c?b:c)?a:(b>c?b:c));

    return 0;
}

发表于 2023-05-20 22:02:14 回复(0)