Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include "subroutines.h"
  2.  
  3. using namespace std;
  4.  
  5. int subroutine_1(string fname_1, string fname_2)
  6. {
  7.     int n = 0;
  8.     fstream fp(fname_1, fstream::in);
  9.     if (!fp.is_open())
  10.         return -1;
  11.  
  12.     fp >> n;
  13.     fp.close();
  14.     if (n <= 0)
  15.         return -10;
  16.  
  17.     double *matrix = new double[n * n];
  18.     if (matrix == NULL)
  19.         return -3;
  20.  
  21.     fp.open(fname_2, fstream::out);
  22.     if (!fp.is_open())
  23.         return -2;
  24.  
  25.     for (int i = 0; i < n; i++) {
  26.         for (int j = 0; j < n; j++) {
  27.             matrix[i * n + j] = (abs(j - 3) - 1.3) * (6.5 - j) * pow(2, j - 1) * (2 * abs(3.3 - i) - 1.5);
  28.         }
  29.     }
  30.  
  31.     for (int i = 0; i < n; i++) {
  32.         for (int j = 0; j < n; j++) {
  33.             fp << std::fixed;
  34.             fp << setw(9) << setprecision(3) << matrix[i * n + j] << " ";
  35.         }
  36.     }
  37.  
  38.     return n;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement