E1 :1x1 + 0x2 +0x3 =2
E2 :0x1 + 1x2 +0x3 =0
E3 :0x1 + 0x2 +1x3 =1
#include <math.h>
void solution( int a[3][4], int var );
int main()
{
int var, i, j, k, l, n;
var=3; //the number of variables: x1,x2,x3
int a[3][4]={
{1,0,0,2},
{0,1,0,0},
{0,0,1,1} };
solution( a, var );
return 0;
}
void solution( int a[3][4], int var )
{
int k, i, l, j;
printf("the orginal function :\n");
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("%4d",a[i][j]);
}
printf("\n");
}
printf("----------------------\n");
}
printf( "\nSolutions:" );
for ( i = 0;i < var;i++ )
{
printf( "\nTHE VALUE OF x%d IS %0.2lf\n", i + 1, ( float ) a[ i ][ var ] / ( float ) a[ i ][ i ] );
}
}
輸出畫面
the orginal function :
1 0 0 2
0 1 0 0
0 0 1 1
----------------------
1 0 0 2
0 1 0 0
0 0 1 1
----------------------
1 0 0 2
0 1 0 0
0 0 1 1
----------------------
Solutions:
THE VALUE OF x1 IS 2.00
THE VALUE OF x2 IS 0.00
THE VALUE OF x3 IS 1.00
沒有留言:
張貼留言