R
R
Ruslan Malkhozov2019-03-01 22:58:02
C++ / C#
Ruslan Malkhozov, 2019-03-01 22:58:02

How to make comparison of 4 numbers easier with if?

The input is four numbers, you need to make sure that the user enters different integers.
How to compose a form like this:

start:
scanf("%d %d %d %d",&a ,&b, &c, &d);
if(a!=b&&a!=c);
    else{
        printf("Not good, repeat\n");
        goto start;
    }
if(a!=d&&b!=d);
    else{
        printf("Not good, repeat\n");
        goto start;
    }
if(b!=c&&c!=d);
    else{
        printf("Not good, repeat\n");
        goto start;
    }

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Tsvetkov, 2019-03-02
@yellow79

You add numbers to a map, set or whatever is in C, then if the length is not equal to the number of input numbers, then there are matches.

S
Sergey delphinpro, 2019-03-02
@delphinpro

$Maccив = ПолучитьМассивЧисел()
ОтсортироватьМассив($Массив)
$Врем = 0
Цикл $Число Из $Массив
  Если $Число == $Врем То 
    Принт("Есть совпадение")
    ОстановитьЦикл
    ВыйтиИзПодпрограммы
  Иначе
    $Врем = $Число

V
Vladimir T, 2019-03-01
@32bit_me

if(a == b || a == c || a == d || b == c || b == d || c == d) {
    printf("Not good, repeat\n");
}
else {
// start hete
// ...
}

V
Vasily Melnikov, 2019-03-03
@BacCM

The easier it is to write, the better. If there are only four values ​​and it is not supposed to change this number. It's easy to write a condition. But it is better to put this check into a properly named function so that the reader of the code understands what is happening.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question