Максимум серед четирьох чисел шукаємо за допомогою умовного оператора.
Реалізація алгоритму
Читаємо вхідні дані.
scanf("%d %d %d %d",&a,&b,&c,&d);Ініціалізуємо значення максимуму першим числом.
max = a;Послідовно порівнюємо інші числа з поточним максимумом. Якщо яке-небудь зі чисел більше максимуму, оновлюємо значення максимуму.
if (b > max) max = b;
if (c > max) max = c;
if (d > max) max = d;Виводимо відповідь.
printf("%d\n",max);Java реалізація
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
int d = con.nextInt();
int res = a;
if (b > res) res = b;
if (c > res) res = c;
if (d > res) res = d;
System.out.println(res);
con.close();
}
}Python реалізація
Читаємо вхідні дані.
a, b, c, d = map(int,input().split())Виводимо максимум чотирьох чисел.
print(max(a,b,c,d))