Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- double ** inputmf(ifstream &f,int n, int m, string s)
- {
- int i,j;
- double **a;
- a=new double *[n];
- for(i=0;i< n;i++)
- {
- a[i]=new double[m];
- }
- f.open(s);
- if (f.fail()) {cout<<"\n Ошибка открытия файла";
- exit(1);
- }
- for(i=0;i< n;i++)
- {for(j=0;j< m;j++)
- f >>a[i][j];
- }
- //Закрытие файла
- f.close();
- return a;
- }
- double* calculate(double** arr,int n, int m) {
- double max;
- double* result = new double[n];
- for (int i = 0; i < n; ++i) {
- max = arr[0][i];
- for (int j = 0; j < m; ++j) {
- if (arr[j][i] > max) max = arr[j][i];
- }
- result[i] = max;
- }
- return result;
- }
- void outputmf(ofstream &f,double *a, int n, string s)
- {
- int i,j;
- f.open(s);
- if (f.fail()) {cout<<"\n Ошибка открытия файла";
- exit(1);
- }
- for(i=0;i< n;i++)
- {
- f<< setw(10)<< a[i];
- }
- f.close();
- }
- int main(){
- string name;
- name = "/home/etryfly/file";
- cout << "Enter file name(path):";
- cin >> name;
- ifstream file;
- int n;
- cout << "Enter n:";
- cin >> n;
- double **arr = inputmf(file, n,n, name);//считали массив из файла
- ofstream ofile;
- double *b = calculate(arr, n, n);
- outputmf(ofile, b, n, name);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement