//KINDLY ASK THE DOUBTS IN COMMENTS
# include<stdio.h>
void subtrac(float b[][6], int k);
float constant(float c[][6], int a, int b);
void divide(float b[][6], int a, float c);
void main()
{
float a[3][6], k = 0.0;
int i, j;
for( i = 0 ;i < 3; i ++)
{
for( j = 0; j < 6; j++)
{
a[i][j] = 0;
}
}
for(j = 0; j < 3; j++)
{
for(i = 0; i < 3;i++)
{
printf("ENTER ELEMENT AT %d x %d\n",j, i);
scanf("%f", &a[j][i]);
}
}
a[0][3] = 1.0;
a[1][4] = 1.0;
a[2][5] = 1.0;
for(i = 0 ; i < 3; i++)
{
subtrac(a,i);
}
for(i = 0; i < 3; i++)
{
k = a[i][i];
divide(a, i, k);
}
for(i = 0 ; i < 3; i++)
{
for(j= 3; j < 6; j++)
{
printf("%f ", a[i][j]);
}
printf("\n");
}
}
void subtrac(float b[][6], int k)
{
int i, z;
float j;
for( i = 0; i < 3; i++)
{
if(i != k)
{
j = constant(b, i , k);
for(z = 0; z < 6; z++)
{
b[i][z] = b[i][z] - j * b[k][z];
}
printf("R%d -> R%d - (%.2f * R%d)\n",i+1,i+1,j,k+1);
}
}
}
float constant(float c[][6], int a, int b)
{
float con;
con = c[a][b]/ c[b][b];
return (con);
}
void divide(float b[][6], int a, float c)
{
int j;
for(j = 0; j < 6; j++)
{
b[a][j] = b[a][j] / c;
}
printf("R%d -> R%d / %.2f\n", a+1, a+1, c);
}
No comments:
Post a Comment