Program 4 5
Program 4 5
# include <stdio.h>
# include <conio.h>
void main()
{
int i, j, k, n ;
float a[20][20], x[20] ;
double s, p ;
printf("Enter the number of equations : ") ;
scanf("%d", &n) ;
printf("\nEnter the co-efficients of the equations :\n\n") ;
for(i = 0 ; i < n ; i++)
{
for(j = 0 ; j < n ; j++)
{
printf("a[%d][%d] = ", i + 1, j + 1) ;
scanf("%f", &a[i][j]) ;
}
printf("b[%d] = ", i + 1) ;
scanf("%f", &a[i][n]) ;
}
for(k = 0 ; k < n - 1 ; k++)
{
RESULT:
Enter the number of equations : 4
a[1][1] = 10
a[1][2] = -7
a[1][3] = 3
a[1][4] = 5
b[1] = 6
a[2][1] = -6
a[2][2] = 8
a[2][3] = -1
a[2][4] = -4
b[2] = 5
a[3][1] = 3
a[3][2] = 1
a[3][3] = 4
a[3][4] = 11
b[3] = 2
a[4][1] = 5
a[4][2] = -9
a[4][3] = -2
a[4][4] = 4
b[4] = 7
The result is :
x[1] = 5.00
x[2] = 4.00
x[3] = -7.00
x[4] = 1.00
Output:
__________________________________________
x1
x2
x3
__________________________________________
0.000000
0.000000
0.000000
0.850000
-1.027500
1.010875
1.002463
-0.999826
0.999780
0.999969
-1.000006
1.000002
__________________________________________
x1 = 1.000
x2 = -1.000
x3 = 1.000