c++ Second largest integer input question

Asked 2 years ago, Updated 2 years ago, 26 views

It's a program that outputs the second largest integer when you receive the cleaning number I think it's going well and there's no error, but I keep getting wrong answers. Please tell me what's wrong

#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>

int main() {

    int x, y, z=0;
    printf ("Enter 3 integers: ");
    scanf("%d %d %d", &x, &y, &z);
    if ((1 <= x, y, z) && (x, y, z <= 100)) {

        if (((x > y) && (z > y) && (x < z)) || ((x > z) && (y > z) && (x < y)) || ((y == z) && (x < y)) || ((x == y) && (x < z)) || ((x == z) && (x < y)))
            printf("%d", x);
        else if (((x > y) && (z > y) && (z < x)) || ((y > x) && (z > x) && (z < y)) || ((x == y) && (z < y)) || ((y == z) && (z < x)) || ((x == z) && (z < y)))
            printf("%d", z);
        else if (((y > x) && (z > x) && (y < z)) || ((x > z) && (y > z) && (y < x)) || ((x == z) && (y < x)) || ((y == x) && (y < z)) || ((y == z) && (y > z)))
            printf("%d", y);
        else printf("%d", x);

    }
    else printf ("Please re-enter")

    return 0;
}

If you do this, you get the second largest number when you enter all three integers, but Baekjun keeps saying that it's wrong.What do you want?

c++

2022-09-22 18:48

2 Answers

if ((1 <= x, y, z) && (x, y, z <= 100)) 

The intention would be x, y, and z in the range between 1 and 100, respectively, and it wouldn't work. No compilation errors or warnings?


2022-09-22 18:48

If I were you, I would make three corrections

1. What if there are overlapping numbers among the three counts?

2. Do not receive back to scanf when "re-enter" appears

If one or more variables other than 3.x, y, and z are added, the code correction increases->for statement may be intended to be more general...?


2022-09-22 18:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.