Friday, July 20, 2012

C Program for Gauss Sedial Method





/* Gauss Sedial Method */

#include<stdio.h>

#include<conio.h>

void main()

{

float a[3][4],i,j,k,sum,x[]={0,0,0};

clrscr();



printf("Enter coeff. in format\nax1+bx2+c3=d");

for(i=0;i<3;i++)

{

for(j=0;j<4;j++)

{

scanf("%f",&a[i][j]);

}

}




for(k=0;k<2;k++)

{

for(i=0;i<3;i++)

{

sum=a[i][3];

for(j=0;j<3;j++)

{

if(i!=j)

sum=sum-a[i][j]*x[j];

}

x[i]=sum/a[i][i];

}

puts("\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");

printf("\nValue After %d Iteration\n",k+1);

for(i=0;i<3;i++)

{

printf("\tx%d=%f",(int)i+1,x[i]);

}

puts("\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");

}

getch();

}










Output Of Program:-

Enter coeff. in format

ax1+bx2+c3=d

3 -0.1 -0.2 7.85

0.1 7 -0.3 -19.3

0.3 -0.2 10 71.4

-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-




Value After 0 Iteration

x1=2.616667 x2=-2.794524 x3=7.005609

-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-




Value After 0 Iteration

x1=2.990556 x2=-2.499624 x3=7.000291

-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-

















No comments:

Post a Comment