Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- int N=4;
- using namespace std;
- double ** f1(ifstream &fin){
- fin >> N;
- cout << "\tИсходная матрица размерностью " << N << "x" << N << endl;
- double ** matr = new double*[N];
- for(int i=0; i<N; i++){
- matr[i] = new double[N];
- for(int j=0; j<N; j++){
- fin >> matr[i][j];
- cout << matr[i][j] << " \n"[j==N-1];
- }
- }
- cout << "\n";
- return matr;
- }
- void f2(double ** &matr, ofstream &fout){
- for(int step=1; step<=N; step++){
- cout << "шаг " << step << ":\n";
- fout << "шаг " << step << ":\n";
- for(int i=step; i<N; i++){
- double cnst=1.*matr[i][step-1]/1./matr[step-1][step-1];
- for(int j=step-1; j<N; j++)
- matr[i][j]-=matr[step-1][j]*cnst;
- }
- for(int i=0; i<N; i++)
- for(int j=0; j<N; j++){
- cout << matr[i][j] << " \n"[j==N-1];
- fout << matr[i][j] << " \n"[j==N-1];
- }
- cout << "\n";
- fout << "\n";
- }
- }
- double f3(double ** &matr){
- double res=1;
- for(int i=0; i<N; i++)
- res*=matr[i][i];
- return res;
- }
- int main(){
- ifstream fin("input.txt");
- ofstream fout("matrgause.txt");
- cout << "\tметод Гаусса\n";
- double ** matr = f1(fin);
- f2(matr, fout);
- cout << "Определитель равен " << f3(matr) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement