Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "subroutines.h"
- using namespace std;
- int subroutine_1(string fname_1, string fname_2)
- {
- int n = 0;
- fstream fp(fname_1, fstream::in);
- if (!fp.is_open())
- return -1;
- fp >> n;
- fp.close();
- if (n <= 0)
- return -10;
- double *matrix = new double[n * n];
- if (matrix == NULL)
- return -3;
- fp.open(fname_2, fstream::out);
- if (!fp.is_open())
- return -2;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- matrix[i * n + j] = (abs(j - 3) - 1.3) * (6.5 - j) * pow(2, j - 1) * (2 * abs(3.3 - i) - 1.5);
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- fp << std::fixed;
- fp << setw(9) << setprecision(3) << matrix[i * n + j] << " ";
- }
- }
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement