Answer the question
In order to leave comments, you need to log in
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
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.
$Maccив = ПолучитьМассивЧисел()
ОтсортироватьМассив($Массив)
$Врем = 0
Цикл $Число Из $Массив
Если $Число == $Врем То
Принт("Есть совпадение")
ОстановитьЦикл
ВыйтиИзПодпрограммы
Иначе
$Врем = $Число
if(a == b || a == c || a == d || b == c || b == d || c == d) {
printf("Not good, repeat\n");
}
else {
// start hete
// ...
}
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 questionAsk a Question
731 491 924 answers to any question