Hello, dear all. My algorithm as follows. my input is in Code2D.h file. actually i have to put in file 'Code2D.in'. but i dont know have to create it. By the way, my algorithm have no problem with N <= 4. but when i change N = 5, 6 , or 7, so on. the output is trouble. is it something is not right?
#include <fstream>
#include <iostream>
#define N 5
using namespace std;
void main()
{
int i,j,k;
double A[N+1][N+1];
cout.setf(ios::fixed);
cout.precision(5);
cout << "Input matrix A: " << endl;
ifstream InFile("Code2D.h");
for (i=1;i<=N;i++)
{
for (j=1;j<=N;j++)
{
InFile >> A[i][j];
cout << A[i][j] << " ";
}
cout << endl;
}
InFile.close();
// row operations
double Product,m;
for (k=1;k<=N-1;k++)
for (i=k+1;i<=N;i++)
{
m=A[i][k]/A[k][k];
for (j=1;j<=N;j++)
A[i][j]-=m*A[k][j];
}
cout << endl << "matrix U:" << endl;
for (i=1;i<=N;i++)
{
for (j=1;j<=N;j++)
cout << A[i][j] << " ";
cout << endl;
}
Product=1;
for (i=1;i<=N;i++)
Product *= A[i][i]; // determinant
// display results
cout << endl << "det(A)=" << Product << endl;
}