include stdio include conio include math define 01 void main int float

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define e 0.01
void main()
{
int i,j,k,n;
float a[10][10],x[10];
float sum,temp,error,big;
printf("Gauss-Seidel iterative method\n\n");
printf("Enter the number of equations: ");
scanf("%d",&n) ;
printf("Enter the coefficients of the equations: \n");
for(i=1;i<=n;i++){
for(j=1;j<=n+1;j++){
printf("a[%d][%d]= ",i,j);
scanf("%f",&a[i][j]);
}
}
for(i=1;i<=n;i++){
x[i]=0;
}
do {
big=0;
for(i=1;i<=n;i++){
sum=0;
for(j=1;j<=n;j++){
if(j!=i){
sum=sum+a[i][j]*x[j];
}
}
temp=(a[i][n+1]-sum)/a[i][i];
error=fabs(x[i]-temp);
if(error>big){
big=error;
}
x[i]=temp;
printf("\nx[%d] =%f",i,x[i]);
}
printf("\n");
}
while(big>=e);
printf("\n\nconverges to solution");
for(i=1;i<=n;i++){
printf("\nx[%d]=%f",i,x[i]);
}
printf("\n");
getch();
}