Загрузка...

Replace negative elements of the first line with (-1), positive elements with 1, and leave zero elements without

Thread in C/C++ created by business_dark Feb 11, 2022. 189 views

  1. business_dark
    business_dark Topic starter Feb 11, 2022 Приложения на айфон взломанные - t.me/ipa_dark 11,757 Nov 26, 2018
    C

    #include <iostream>

    using namespace std;

    int main(){
    setlocale(LC_ALL,"Russian");
    const int m = 3, n = 2;
    int mas[m][n];

    for(int i = 0; i < m; i++)
    for(int j = 0; j < n; j++){
    cout << "mas[" << i << "][" << j << "] = ";
    cin >> mas[i][j];
    }

    cout << "\n\nВывод массива: \n";
    for(int i = 0; i < m; i++){
    cout << "\n";
    for(int j = 0; j < n; j++)
    cout << mas[i][j] << " ";
    }

    for(int j = 0; j < n; j++)
    mas[0][j] = -1;

    cout << "\n\nВывод массива: \n";
    for(int i = 0; i < m; i++){
    cout << "\n";
    for(int j = 0; j < n; j++)
    cout << mas[i][j] << " ";
    }
    return 0;
    }

    Вот что я накидал
    думаю иду в верном направлении. Загуглил уже всё, не могу найти. Как мне сделать условие если массив > 0..?
    если массив mas[0][j] > 0
    тогда mas[0][j] (Первой строке) присвоить значение 1

    for(int j = 0; j < n; j++)
    mas[0][j] = -1;
     
  2. YungSabb
    YungSabb Feb 11, 2022 Banned 1 Feb 10, 2022
    А какая вообще задача?
     
  3. Daemon
    Daemon Feb 11, 2022 1680 Jan 8, 2021
    business_dark,
    C
    #include <iostream>

    using namespace std;

    int main(){
    setlocale(LC_ALL,"Russian");
    const int m = 3, n = 2;
    int mas[m][n];

    for(int i = 0; i < m; i++)
    for(int j = 0; j < n; j++){
    cout << "mas[" << i << "][" << j << "] = ";
    cin >> mas[i][j];
    }

    cout << "\n\nВывод массива: \n";
    for(int i = 0; i < m; i++){
    cout << "\n";
    for(int j = 0; j < n; j++)
    cout << mas[i][j] << " ";
    }

    for(int j = 0; j < n; j++)
    if(mas[0][j] > 0) mas[0][j] = 1;
    else if (mas[0][j] < 0) mas[0][j] = -1;

    cout << "\n\nВывод массива: \n";
    for(int i = 0; i < m; i++){
    cout << "\n";
    for(int j = 0; j < n; j++)
    cout << mas[i][j] << " ";
    }
    return 0;
    }
     
    1. View previous comments (2)
    2. Daemon
      business_dark, Строка это горизонталь - красная стрелка на картинке. Что не так?
Top
Loading...