Advertisement
fabis_sparks

Sevastyanov32

Dec 22nd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. // Sevastyanov32.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <math.h>
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "Russsian");
  13.     double a[4][4];
  14.     int i, j;
  15.     cout.precision(2); // установим количество знаков после запятой
  16.     for (i = 0; i < 4; i = i + 1) {
  17.         for (j = 0; j < 4; j = j + 1) {
  18.             a[i][j] = sin(2.1*i - j);
  19.             cout << setw(8) << a[i][j];
  20.         }
  21.         cout << endl;
  22.     }
  23.     // Найдём сумму отриц элементов на побочной диагонали
  24.     j = 0;
  25.     double sum = 0;
  26.     for (i = 3;i > -1;i=i-1) {
  27.         if (a[i][j] < 0) sum = sum + a[i][j];
  28.         j=j+1;
  29.         }
  30.     cout << "Sum of negative elems equals: " << sum << endl;
  31.     // Найдем макс элемент во втором столбце и его позицию
  32.     int i_max = 0;
  33.     int j_max = 1;
  34.     int max = a[i_max][j_max]; // запишем в максимум 0ой элемент второго столбца для сравнения с остальными
  35.     for (i = 0;i < 4;i=i+1) {
  36.         if (a[i][1] > max) {
  37.             max = a[i][1];
  38.             i_max = i;
  39.         }
  40.     }
  41.     cout << "Position of max elem in 2nd column: X: " << i_max + 1 << " Y: -" << j_max << endl;
  42.     // Заменим максимальный элемент второго столбца на знач суммы
  43.     a[i_max][j_max] = sum;
  44.     // Выведем полученную матрицу
  45.     for (i = 0;i < 4;i=i+1) {
  46.         for (j = 0; j < 4;j=j+1) {
  47.             cout << setw(8) << a[i][j];
  48.         }
  49.         cout << endl;
  50.     }
  51.     system("pause");
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement