Загрузка...

Where is the error?

Thread in C/C++ created by DTMinfinix Oct 23, 2024. 211 views

  1. DTMinfinix
    DTMinfinix Topic starter Oct 23, 2024 20 Oct 16, 2024
    Вводится число int
    Если в числе есть 4 (например 1943), выводит YES
    Иначе NO

    C
    #include <iostream>

    using namespace std;

    int main() {
    int n, x, flag;
    cin >> n;

    do {
    x = n % 10;
    n /= 10;

    if (x == 4) {
    flag = 1;
    }
    } while (x != 0);

    if (flag == 1) {
    cout << "YES";
    }
    else {
    cout << "NO";
    }
    }
     
  2. Монополист
    Монополист Oct 23, 2024 https://lolz.live/threads/8640118/ - обмен всего и вся 9724 Mar 6, 2021
    Code
    #include <iostream>

    using namespace std;

    int main() {
    int n, x;
    bool flag = false;
    cin >> n;

    if (n < 0) {
    n = -n;
    }

    do {
    x = n % 10;
    n /= 10;

    if (x == 4) {
    flag = true;
    }
    } while (n != 0);

    if (flag) {
    cout << "YES";
    } else {
    cout << "NO";
    }

    return 0;
    }
     
Loading...
Top