-
Notifications
You must be signed in to change notification settings - Fork 1
/
gausselimination.c
48 lines (47 loc) · 977 Bytes
/
gausselimination.c
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
#include<stdio.h>
int main()
{
int i,j,k,n;
float M[20][20],c,x[10],sum=0.0;
printf("\nENTER THR ORDER OF MATRIX: ");
scanf("%d",&n);
printf("\nENTER THE ELEMENTS OF MATRIX :\n\n");
for(i=1; i<=n; i++)
{
for(j=1; j<=(n+1); j++)
{
printf("M[%d][%d] : ", i,j);
scanf("%f",&M[i][j]);
}
}
for(j=1; j<=n; j++)
{
for(i=1; i<=n; i++)
{
if(i>j)
{
c=M[i][j]/M[j][j];
for(k=1; k<=n+1; k++)
{
M[i][k]=M[i][k]-c*M[j][k];
}
}
}
}
x[n]=M[n][n+1]/M[n][n];
for(i=n-1; i>=1; i--)
{
sum=0;
for(j=i+1; j<=n; j++)
{
sum=sum+M[i][j]*x[j];
}
x[i]=(M[i][n+1]-sum)/M[i][i];
}
printf("\nANSWER: \n");
for(i=1; i<=n; i++)
{
printf("\nx%d=%f\n",i,x[i]);
}
return 0;
}