GAUSS SEIDEL METHOD
/* Note: The system of equations must be diagonally dominant */
void main()
{
/* Variable declaration */
int n,p,i,j,m;
float a[10][10], x[10], b[10], c;
clrscr();
printf("Enter the number of variables");
scanf("%d", &n);
printf("enter the number of required iterations\n");
scanf("%d",&p);
printf("enter the right hand side matrix\n");
/* loop to read right-hand side constants */
for(i=0; i<n; i++)
{
scanf("%f", &b[i]);
}
/* Loops to read coefficient matrix */
printf("enter the left hand side matrix");
for(i=0; i<n; i++)
{
x[i]=0;
for(j=0; j<=n-1; j++)
{
scanf("%f", &a[i][j]);
}
}
/* Execution of Seidel iterations */
m=1;
line:
for(i=0; i<n; i++)
{
c=b[i];
for(j=0; j<n; j++)
{
if(i!=j)
c=c-a[i][j]*x[j];
}
x[i]=c/a[i][i];
printf("\n Solution: x[%d]=%f", i, x[i]);
}
m++;
if(m<=p)
goto line;
else
{
printf("\n required iterations completed");
}
getch();
}