Praktikum_mf

Логические операции: сравнение / Задание 1

Dec 14th, 2021
2,654
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n1, n2, sum;
  7.     cin >> n1 >> n2 >> sum;
  8.    
  9.     int expected_sum = n1 + n2;
  10.     if (sum != expected_sum) {
  11.         cout << "Error. The sum of "s << n1 << " and "s << n2 << " is "s  << expected_sum << endl;
  12.     }
  13. }
Advertisement
Comments
  • nakatoyato
    3 years
    # C++ 0.34 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     int number_1, number_2, sum;
    7.     cin >> number_1 >> number_2 >> sum;
    8.     int current_sum = number_1 + number_2;
    9.     if (number_1 + number_2 != sum) {
    10.          cout << "Error. The sum of "s << number_1 << " and "s << number_2 << " is "s << current_sum << endl;
    11.     }
    12. return 0;
    13. }
  • delix777
    3 years
    # C++ 0.56 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     int x, y, sum;
    7.     // Считайте три целых числа: X и Y и их сумму
    8.     cin >> x >> y >> sum;
    9.     // Если сумма указана неверно, выведите сообщение: "Error. The sum of X and Y
    10.     // Вместо символов X, Y и Z выведите числа X и Y, а также правильное значение суммы
    11.     if ( (x + y) != sum ){
    12.         cout << "Error. The sum of "s << x << " and "s << y << " is "s << x + y;
    13.     }
    14. }
  • ZateRok
    3 years
    # C++ 0.90 KB | 0 0
    1. // Почему этот код не проходит, а проходит какой то левый код???
    2. #include <iostream>
    3.  
    4. using namespace std;
    5.  
    6. int main() {
    7.     long double x, y, z;
    8.     cin >> x >> y >> z;
    9.     long double r = x + y;
    10.     if (r != z) {
    11.         cout << "Error. The sum of "s << x << " and "s << y << " is "s << r << endl;
    12.     }
    13. }
    14.  
    15.  
    16. // тот самый левый код.....................
    17.  
    18. #include <iostream>
    19.  
    20. using namespace std;
    21.  
    22. int main() {
    23.  
    24. int x,y,z,sum,w;
    25.  
    26. cin>>x>>y>>z;
    27. w=x+y;
    28. sum=z;
    29. if(x+y!=sum)
    30. {
    31. cout<<"Error. The sum of "<< x << " and "<< y << " is " << w <<endl;
    32. }
    33. else {
    34. cout<<"";
    35. }
    36. return 0;
    37. }
    38.  
    39.  
    40. // так... я понял почему не работало, я косякнул, с кем не бывает, но на эмуляторе все работало стабильно... хз чем не понравилось забивание через сайт
  • ZateRok
    3 years
    # text 0.26 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6. int x, y, z ;
    7. cin >> x >> y >> z;
    8. int r = x + y;
    9. if ((x + y) != z){
    10. cout << "Error. The sum of "s << x << " and "s << y << " is "s << r << endl;
    11. }
    12.  
    13. }
    14. // теперь и мой прошел
Add Comment
Please, Sign In to add comment