#include <iostream.h>
#include <windows.h>
#include <math.h>

//////////////////////////////////
template<class T>
T* SolveMat(T* mat,int size)
{

	int z=size;

	for(int n=0;n<=z-2;n++)
	{
		for(int q=n+1;q<=z-1;q++)
		{

		T num=(-mat[q*(z+1)+n]/mat[n*(z+1)+n]);
			for(int p=0;p<=z;p++)
			{
				mat[q*(z+1)+p]+=
					num*mat[n*(z+1)+p];
			}
		}
	}
	int E=0;
	T *B=new T[size+1];
	
	for(int q=z-1;q>=0;q--)
	{	
		E=0;
		for(int t=q+1;t<=z-1;t++)
			E+=mat[q*(z+1)+t]*B[t];

		B[q]=(mat[(q+1)*(z+1)-1]-E)/mat[q*(z+1)+q];
	}

//Display The Solution... B[n]

	for(int y=0;y<size;y++)
		cout<<B[y]<<"   ";
return B;

}

void main()
{

//int * mat=new int [10];

 int SIZE=4;
 cout <<"Enter The Number Of The Mat Equtions :";cin>>SIZE;

double *mat=new double[SIZE*(SIZE+1)]; //={1,1,1,2,1,2,4,8,1,3,9,18};

for(int e=0;e<SIZE*(SIZE+1);e++)
cin>>mat[e];

//srand(99);
//for(int q=0;q<SIZE;q++)
//mat[q]=rand()%10;

SolveMat(mat,SIZE);

//for freezing the screen ....
cin>>mat[0];

}

