//Include Files go here
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <math.h>
#include <iostream>

//End include files

//Global constants go here
const int max_file_name = 100;
const double pi = atan(1.0)*4;
const int max_line_length = 100;
const int max_name_length = 50;
const int max_descript_length = 80;
// End Globals

using namespace std;
//g++ simple.cpp -o simple <--- this will compile and link it!

//Main program goes here
int main(int argc, char *argv[])
{
	//a is coeff matrix
	//b is the RHS vector
	//n is the rows/columns of a	
	//x is the solution vector
	//tol is the tolerance -- 
	//er is the error code
	
	//We have n -- set up the arrays
	
	int n = 3, p = 0;
	double a[n][n], x[n], s[n], b[n];
	double tol = 1e-8;
	int er = 0;
	double factor = 0, big = 0;
	for(int i=0; i<n ; i++)
	{
		s[i] = fabs(a[i][0]);
		for(int j=1; j<n; j++)
		{
			if(fabs(a[i][j])>s[i])
				s[i] = 	fabs(a[i][j]);
		}
	}
	
	//Eliminate
	for(int k = 0; k<n-1; k++)
	{
		//pivot
		p = k;
		big = fabs(a[k][k]/s[k]);
		for(int ii = k+1; ii<n; ii++)
		{
			dummy = fabs(a[ii][k]/s[ii]);
			if(dummy > big)
			{
				big = dummy;
				p = ii;
			}
		}
		if(p!=k)
		{
			for(int jj=k; jj<n; jj++)
			{
				dummy = a[p][jj];
				a[p][jj] = a[k][jj];
				a[k][jj] = dummy;
			}
			dummy = b[p];
			b[p] = b[k];
			b[k] = dummy;
			dummy = s[p];
			s[p] = s[k];
			s[k] = dummy;
		}
		//end pivot			
		
		if(fabs(a[k][k]/s[k])<tol)
		{
			er = -1;
			exit(0);
		}
		for(int i=k+1; i<n; i++)
		{
			factor = a[i][k]/a[k][k];
			for(int j = k+1; j <n; j++)
			{
				a[i][j] = a[i][j]-factor*a[k][j];
			}
			
		
			



return 1;
	

}























