How to make matriks properly

hi, i have a problem with matriks. i wrote matriks code in c++ like this:

1
2
3
4
5
6
7
8
9
for (int i;i<dimension;i++)
  {
   for (int j;j<dimension;j++)
    {
      matriks[i][j];
      cout << setw(10) << matriks[i][j] << setprecition(2);
    }
      cout << endl;
  }  


i use "setw(10)" (from library iomanip) to make space between matriks's elements. i print it out on txt file using fstream (ofcourse in my actual code, i didnt write "cout" for output). it worked well when my matriks have non negatife sign. but when i do an algorithm (householder transformation), the value of matriks has negative sign and the "view"(i dont know the engish word for this, i am not native.so i use the word "view" :D ) become like this :

1 3 0 0
3 -5 0 0
-8 -9 -11 -3
2 2 3 0

when i increase the number of "setw" the view of matriks change to "right view". but when the dimension of matriks is big. for example 100x100 matriks, no matter how much i increase the number on "setw" (i have increase to setw(150) ). the matriks view didnt show the "right view".
so, my question is: do anyone know how to solve this problem? do i have to change file type (not txt)? or change "setw" to something else? or is there another way?

thank you folks
Last edited on
Topic archived. No new replies allowed.