I'm writing a Gaussian Elimination process for a given matrix, and seem to have gotten the numbers correct. Unfortunantly, the results are printed in a continuous line across the screen, without breaks in rows. Here's my code:
Code:
#include <stdio.h>
main()
{
FILE *infile;
int cols, rows, col, row;
double v0[20], v[20], w0[20], w[20];
infile = fopen("matrix0.dat", "r");
if(infile==NULL) {
printf("The file, 'matrix0.dat', was not found\n");
exit(0);
}
fscanf(infile, "%d" "%d", &rows, &cols);
for(col=0; col<cols; col++){
fscanf(infile, "%lf",&v0[col]);
v[col] = v0[col]/v0[0];
printf("%7.2f", v[col]);
}
printf("\n");
while(!feof(infile)){
for(col=0; col<cols; col++){
fscanf(infile, "%lf", &w0[col]);
w[col] = w0[col] - w0[0]*v[col];
printf("%7.2f", w[col]);
}
}
printf("\n");
}
I would like to be able to break the w[col] results into rows of 10 each, but I haven't been able to accomplish that using a printf("\n") anywhere. Any help or suggestions would be appreciated.