Originally Posted by
whiteflags
In what way is it printing wrong? I am not a mind reader.
You are right.
here's what I've done and I'm pretty much pleased to help me:
Code:
#include<stdio.h>
#include<conio.h>
#include <assert.h>
float matrix[10][10], m, temp[10];
int i, j, k, n;
void upper_triangularization() {
for (i = 0; i<n - 1; i++)
for (j = i + 1; j<n; j++)
{
if (matrix[i][i] == 0) // if the matrix[i][i] =0 of the diagonal then the ratio of what m included is always 0, because 0/a=0 always //
{
assert(matrix[i][i] != 0.0 && "division by zero detected!");
m = 0;
}
else
m = matrix[j][i] / matrix[i][i];
for (k = 0; k < n + 1; k++) {
matrix[j][k] = matrix[j][k] - (m*matrix[i][k]);}
}
} //upper_traingulisation
void main() {
printf("Enter number. of column :: ");
scanf("%d", &n);
printf("Enter the augmented matrix: \n");
for (i = 0; i<n; i++)
for (j = 0; j<n ; j++)
scanf("%f", &matrix[i][j]);
upper_triangularization();
printf("The upper traingular matrix is : \n");
for (i = 0; i<n; i++) {
for (j = 0; j<n; j++)
printf("%f \t", matrix[i][j]);
printf("\n");
}
getch();
}
I'm still getting wrong printf in one specific given matrix which is
0 1
1 0 and the printf must be
1 0
0 1
but unfortunately it's printing something weird.