Introduction
Gauss-siedel method to solve system of equations

The code
Code: Cpp
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define N 100
#define ACC 0.000001
/************************************************************/
/***** Gauss-siedel method to solve system of equations *****/
/************************************************************/
void main()
{
float coeff[N][N+1]={{4,2,1,11},{3,5,3,22},{2,3,4,20},};
/* Co-efficient inputing variables */
float x[N]={0,0,0}; /* values of the variables i.e. x's */
int n=3; /* Number of equations */
int i,j; /* Loop variables */
float acc; /* Accuracy determining variable */
char ch; /* choice inputing variable */
do
{
printf("\nEnter the number of variables\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("\nEnter %d row %d col element\n",i+1,j+1);
scanf("%f",&arr[i][j]);
}
}
do
{
acc=coeff[0][n];
for(i=0;i<n;i++)
{
x[i]=coeff[i][n];
for(j=0;j<n;j++)
{
if(i==j)
continue;
x[i]=x[i]-coeff[i][j]*x[j];
}
x[i]=x[i]/coeff[i][i];
}
for(i=0;i<n;i++)
acc=acc-coeff[0][i]*x[i];
}while(fabs(acc)>=ACC);
for(i=0;i<n;i++)
printf("%g\t",x[i]);
printf("\nDo you wish to continue[y/n]\n");
fflush(stdin);
scanf("%c",&ch);
}while(ch=='Y' || ch=='Y');
getch();
}


