If19. Решебник Абрамяна М. Э.
If19. Даны четыре целых числа, одно из которых отлично от трех других, равных между собой. Определить порядковый номер числа, отличного от остальных.
Решение Python
Python # Input four integers num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) num3 = int(input("Enter the third number: ")) num4 = int(input("Enter the fourth number: ")) # Determine the ordinal number of the different number if num1 == num2 == num3: different_ordinal = 4 elif num1 == num2 == num4: different_ordinal = 3 elif num1 == num3 == num4: different_ordinal = 2 else: different_ordinal = 1 # Output the ordinal number of the different number print(f"The number different from the other three is in position: {different_ordinal}")123456789101112131415161718# Input four integersnum1 = int(input("Enter the first number: "))num2 = int(input("Enter the second number: "))num3 = int(input("Enter the third number: "))num4 = int(input("Enter the fourth number: ")) # Determine the ordinal number of the different numberif num1 == num2 == num3: different_ordinal = 4elif num1 == num2 == num4: different_ordinal = 3elif num1 == num3 == num4: different_ordinal = 2else: different_ordinal = 1 # Output the ordinal number of the different numberprint(f"The number different from the other three is in position: {different_ordinal}")
Решение Pascal
Delphi/Pascal program if19; var A, B, C, D: Real; begin Write('Введите первое число: '); Readln (A); Write('Введите второе число: '); Readln (B); Write('Введите третье число: '); Readln (C); Write('Введите четвёртое число: '); Readln (D); if (B=C) and (C=D) then Writeln('1'); if (A=C) and (C=D) then Writeln('2'); if (A=B) and (B=D) then Writeln('3'); if (A=B) and (B=C) then Writeln('4'); end.123456789101112131415161718192021program if19;var A, B, C, D: Real;begin Write('Введите первое число: '); Readln (A); Write('Введите второе число: '); Readln (B); Write('Введите третье число: '); Readln (C); Write('Введите четвёртое число: '); Readln (D); if (B=C) and (C=D) then Writeln('1'); if (A=C) and (C=D) then Writeln('2'); if (A=B) and (B=D) then Writeln('3'); if (A=B) and (B=C) then Writeln('4');end.
Решение C
C #include <stdio.h> int main(void) { int a1, a2, a3,a4; printf("1:"); scanf ("%i", &a1); printf("2:"); scanf ("%i", &a2); printf("3:"); scanf ("%i", &a3); printf("4:"); scanf ("%i", &a4); if (a2 == a3==a4) printf("%i\n",1); else if (a1==a3==a4) printf("%i\n",2); else if (a1==a2==a4) printf("%i\n",3); else printf("%i\n",4); return 0; }123456789101112131415161718192021#include <stdio.h> int main(void){ int a1, a2, a3,a4; printf("1:"); scanf ("%i", &a1); printf("2:"); scanf ("%i", &a2); printf("3:"); scanf ("%i", &a3); printf("4:"); scanf ("%i", &a4); if (a2 == a3==a4) printf("%i\n",1); else if (a1==a3==a4) printf("%i\n",2); else if (a1==a2==a4) printf("%i\n",3); else printf("%i\n",4); return 0;}
Решение C++
C # include <iostream> # include <windows.h> # include <cmath> using namespace std; int main () { SetConsoleCP(1251); SetConsoleOutputCP(1251); int a, b, c, d; int n; cout << "Введите четыре целых числа, одно из которых отлично от трех других: " << endl; cout << "Введите первое число a: "; cin >> a; cout << "Введите второе число b: "; cin >> b; cout << "Введите третье число c: "; cin >> c; cout << "Введите четвертое число d: "; cin >> d; if (a == b && b == c) n = 4; else if (a == b && a == d) n = 3; else if (a == c && a == d) n = 2; else if (b == c && b == d) n = 1; cout << "порядковый номер числа, отличного от остальных: " << n << endl; system ("pause"); return 0; }1234567891011121314151617181920212223242526272829303132# include <iostream># include <windows.h># include <cmath> using namespace std; int main () { SetConsoleCP(1251); SetConsoleOutputCP(1251); int a, b, c, d; int n; cout << "Введите четыре целых числа, одно из которых отлично от трех других: " << endl; cout << "Введите первое число a: "; cin >> a; cout << "Введите второе число b: "; cin >> b; cout << "Введите третье число c: "; cin >> c; cout << "Введите четвертое число d: "; cin >> d; if (a == b && b == c) n = 4; else if (a == b && a == d) n = 3; else if (a == c && a == d) n = 2; else if (b == c && b == d) n = 1; cout << "порядковый номер числа, отличного от остальных: " << n << endl; system ("pause"); return 0;} Оцените решение (3 оценок, среднее: 3,67 из 5) Загрузка...