Матрицю на с++ замінити всі єлементи, які більше 2.5 на -1

Ответы

Ответ дал: Andrey36789
0

#include <iostream>

using namespace std;

 

int main()

{

   int A[3][3] = { {2, 3, 4},

                   {5, 6, 7},

                   {8, 9, 10} };

 

   for (int i = 0; i < 3; i++) {

       for (int j = 0; j < 3; j++) {

           if (A[i][j] > 2.5)

               A[i][j] = -1;

       }

   }

   cout << "Нова матриця: \n";  

   for (int i = 0; i < 3; i++) {  

       for (int j = 0; j < 3; j++)  

           cout << A[i][j] << " ";  

       cout << endl;  

   }  

   return 0;  

}

Ответ дал: asilvejstruk
1

#include <iostream>

using namespace std;

int main() {

   double arr[6][4];

   for (int i = 1; i<=5; i++) {

   for (int j = 1; j<=3; j++) {

       cout << "Введите " << i << " рядок " << j << " стовпчік";

       cin >> arr[i][j];

   }

   }

   for (int i = 1; i<=5; i++) {

   for (int j = 1; j<=3; j++) {

       if (arr[i][j] > 2.5) arr[i][j] = -1;

       cout << arr[i][j] << endl;

   }

   }

   return 0;

}

Вас заинтересует