Другие языки программирования и технологии
сравнение трех целых чисел в C++
Используя оператор IF(без else), нужно написать программу на языке C++ которая принимает три целых числа и выводит большее и меньшее из этих чисел. Подскажите пожалуйста.
1 2 3
x y z
if( x > y && x > z)
вывод x - max
if( x < y && x < z)
вывод x - min
ну и еще 4 таких ифа ...хотя думаю можно изваратится к более компактной записи
x y z
if( x > y && x > z)
вывод x - max
if( x < y && x < z)
вывод x - min
ну и еще 4 таких ифа ...хотя думаю можно изваратится к более компактной записи
без базара пиши в агент
Ну и в чом проблема :))
Conditionally executes a group of statements, depending on the value of an expression.
if (condition)
statement1
[else
statement2]
Arguments
condition
Required. A Boolean expression. If condition is null or undefined, condition is treated as false.
statement1
Optional. The statement to be executed if condition is true. Can be a compound statement.
statement2
Optional. The statement to be executed if condition is false. Can be a compound statement.
Remarks
It is generally good practice to enclose statement1 and statement2 in braces ({}) for clarity and to avoid inadvertent errors.
Example
In the following example, you may intend that the else be used with the first if statement, but it is used with the second one.
if (x == 5)
if (y == 6)
z = 17;
else
z = 20;
Changing the code in the following manner eliminates any ambiguities:
if (x == 5)
{
if (y == 6)
z = 17;
}
else
z = 20;
Similarly, if you want to add a statement to statement1, and you don not use braces, you can accidentally create an error:
if (x == 5)
z = 7;
q = 42;
else
z = 19;
In this case, there is a syntax error, because there is more than one statement between the if and else statements. Braces are required around the statements between if and else.
Conditionally executes a group of statements, depending on the value of an expression.
if (condition)
statement1
[else
statement2]
Arguments
condition
Required. A Boolean expression. If condition is null or undefined, condition is treated as false.
statement1
Optional. The statement to be executed if condition is true. Can be a compound statement.
statement2
Optional. The statement to be executed if condition is false. Can be a compound statement.
Remarks
It is generally good practice to enclose statement1 and statement2 in braces ({}) for clarity and to avoid inadvertent errors.
Example
In the following example, you may intend that the else be used with the first if statement, but it is used with the second one.
if (x == 5)
if (y == 6)
z = 17;
else
z = 20;
Changing the code in the following manner eliminates any ambiguities:
if (x == 5)
{
if (y == 6)
z = 17;
}
else
z = 20;
Similarly, if you want to add a statement to statement1, and you don not use braces, you can accidentally create an error:
if (x == 5)
z = 7;
q = 42;
else
z = 19;
In this case, there is a syntax error, because there is more than one statement between the if and else statements. Braces are required around the statements between if and else.
Похожие вопросы
- Даны 3 целых числа найти среднее язык #C
- Проверте программу, которая вычисляет сумму целых чисел от а до 500 (значение a вводится с клавиатуры). c++
- Как вычленить из строки два целых числа? C++
- даны 3 разл целых числа a,b,c используя оператор GOTO составить программу для ввода чисел в порядке убывания
- Вам даны все целые числа от 1 до N + 1, кроме одного. Найдите отсутствующее число.
- C# Дан массив Х из 50 целых чисел.
- помогите решить задачу!...Даны целые числа a, b, c, являющиеся сторонами некоторого треугольника.Проверить истинность вы
- Дан файл целых чисел. Создать два новых файла, первый из которых содержит положительные числа из исходного файла...
- помогите? Дан массив целых чисел (n=15),
- Объявить массив целых чисел и заполнить его случайными значенниями.