Gauss-Seidel

Gauss-Seidel Method

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main (void)
{
	float a[10][10],x[5],c[5],add,e=1,f;
   int i,j,ct=0;
   clrscr();
   printf("Enter the coefficient and const Matrix wise for 3 eq:\n");
   for(i=1;i<=3;i++)
   	for(j=1;j<=4;j++)
      	scanf("%f",&a[i][j]);
   f=x[1];
   while(e>=0.001)
   {

   	for(i=1;i<=3;i++)
   	{
         add=0.0;
   		for(j=1;j<=3;j++)
      	{
            if(i!=j)
      		add+=(a[i][j]*x[j]);
      	}
         add=a[i][4]-add;
      	c[i]=add/a[i][i];       printf("\nx[i]=%f",c[i]);
   	}
      printf("\n");
      for(i=1;i<=3;i++)
      {
      	x[i]=c[i];        
      }
   	e=fabs(x[1]-f);
      f=x[1];
      ct++;
   }
   printf("\nItaration no. is: %d\n",ct);
   printf("Required ans is:\n%f\n%f\n%f",x[1],x[2],x[3]);
   getch();
   return 0;
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *