Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C code for the following to solve the following 10 simultaneous equation

ID: 3821148 • Letter: W

Question

Write a C code for the following to solve the following 10 simultaneous equations by the Gauss-Jordan elimination method

a11x1+a12x2+a13x3+......+a1 10x10=c1

a21x1+a22x2+a23x3+......+a2 10x10=c2

a31x1+a32x2+a33x3+......+a3 10x10=c1

……………………………………

an1x1+an2x2+an3x3+......+a10 10x10=c10

Data are given here

1 continued: aij is given as

a[10][10]={

{3.55618, 5.87317, 7.84934, 5.6951, 3.84642, 9.15038, -1.68539, 5.03067, 7.63384, -1.75626},

{-4.82893, 8.38177, -0.301221, 5.10182, -4.1169,-6.09145, -3.95675, -2.33365, 1.3969, 6.54555},

{-7.64196, 5.66605,3.20481, 1.55619, -1.19814, 9.79288, 5.35547, 5.86109, 4.95544, -9.35749},

{-2.95914, -9.16958,7.3216, 2.39876, -8.1302, -7.55135, -2.37718, 7.29694, 5.9867, 8.5401},

{-8.42043, -0.369407, -5.4102, -8.00545, 9.22153, 3.96454, 5.38499, 0.438365, 0.419677, 4.17166},

{6.02952, 4.57728, 5.46424, 3.52915, -1.01135, -3.74686,8.14264, -8.86961, -2.88114, 1.29821},

{0.519819, -6.16655, 1.13216, 2.75811, -1.05975, 4.20286, -3.45764, 0.763558, -0.281287, -9.76168},

{5.15737, -9.67481, 9.29904, -3.93334, 9.12785, -4.25208, -6.1652, 2.5375, 0.139195, 2.00106},

{-4.30784, 1.40711, -6.97966, -9.29715, 5.17234, 2.42634, 1.88818, -2.05526, -3.7679, 3.3708},

{-4.65418, 7.18118, 6.51338, 3.13249, 0.188456, -16.85599, 7.21435, -2.93417, 1.06061, 1.10807}

};

and ci is given as

c[10]={-1.92193, -2.35262, 2.27709, -2.67493, 1.84756, 4.154126, -0.93387, -1.28356, -3.46841, -2.61529};

Explanation / Answer



#include<stdio.h>
#include<conio.h>
void solution( int a[][], int var );
int main()
{

int a[ 10 ][ 10 ]=a[10][10]={
{3.55618, 5.87317, 7.84934, 5.6951, 3.84642, 9.15038, -1.68539, 5.03067, 7.63384, -1.75626},
{-4.82893, 8.38177, -0.301221, 5.10182, -4.1169,-6.09145, -3.95675, -2.33365, 1.3969, 6.54555},
{-7.64196, 5.66605,3.20481, 1.55619, -1.19814, 9.79288, 5.35547, 5.86109, 4.95544, -9.35749},
{-2.95914, -9.16958,7.3216, 2.39876, -8.1302, -7.55135, -2.37718, 7.29694, 5.9867, 8.5401},
{-8.42043, -0.369407, -5.4102, -8.00545, 9.22153, 3.96454, 5.38499, 0.438365, 0.419677, 4.17166},
{6.02952, 4.57728, 5.46424, 3.52915, -1.01135, -3.74686,8.14264, -8.86961, -2.88114, 1.29821},
{0.519819, -6.16655, 1.13216, 2.75811, -1.05975, 4.20286, -3.45764, 0.763558, -0.281287, -9.76168},
{5.15737, -9.67481, 9.29904, -3.93334, 9.12785, -4.25208, -6.1652, 2.5375, 0.139195, 2.00106},
{-4.30784, 1.40711, -6.97966, -9.29715, 5.17234, 2.42634, 1.88818, -2.05526, -3.7679, 3.3708},
{-4.65418, 7.18118, 6.51338, 3.13249, 0.188456, -16.85599, 7.21435, -2.93417, 1.06061, 1.10807}
};
int c[10]={-1.92193, -2.35262, 2.27709, -2.67493, 1.84756, 4.154126, -0.93387, -1.28356, -3.46841, -2.61529};
int var, i, j, k, l;
clrcsr();
printf( " Enter the number of variables: " );
scanf( "%d", &var );//here it will be 10

for ( i = 0;i < var;i++ )
{
printf( " Enter the equation%d: ", i + 1 );

for ( j = 0;j < var;j++ )
{
printf( "Enter the coefficient of x%d: ", j + 1 );
scanf( "%d", &a[ i ][ j ] );
}

printf( " Enter the constant: " );
scanf( "%d", &c[i] );
}

solution( a, var );
return 0;
}



void solution( int a[ 10 ][ 10 ], int var )
{
int k, i, l, j;

for ( k = 0;k < var;k++ )
{
for ( i = 0;i <= var;i++ )
{
l = a[ i ][ k ];

for ( j = 0;j <= var;j++ )
{
if ( i != k )
a[ i ][ j ] = a[ k ][ k ] * a[ i ][ j ] – l * a[ k ][ j ];
}
}
}

printf( " Solutions:" );

for ( i = 0;i < n;i++ )
{
printf( " THE VALUE OF x%d IS %f ", i + 1, ( float ) a[ i ][ n ] / ( float ) a[ i ][ i ] );
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote