Issues with changing values in an array

This a segment of the code i can post all of it if it will help
I'm trying to invert a matrix i'm going to use elementary row operations so i have to make an identity matrix beside it.

Here is the process i'm following. http://www.purplemath.com/modules/mtrxinvr.htm

The thing is when i output the matrix for example a 3x6 matrix it will output
123100
123010
123001

lines 2 and 3 are just the same as line 1 no matter what i make lines 2 and 3. I think its something to do with line 27 but i'm not sure.

Sorry about all the comments that was me playing with it trying to fix it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
else
    {
      // rows=rows-1;
     
      //int array[(rows*2)+1][rows+1];
      int cols=(rows*2)-1;
      int array[rows][cols+1];
      int v=0;
      for (int x=0; x <=(cols)  &&  v <= (rows); x++)
	{
	  array[v][x]=0;
	  
	  if (x==(cols))
	      {
		x=-1;
		  v=v+1;
	      }
	}
      /////////////////////////////////////////////////
        int y=0;
       int z=0;
       int i=0;
       for (int x=0; x<= cols, y<=rows; x++)
      	  {
	    //cout << d[0,3] << endl;
	    // array[y][x]=(*(d+z));
	    array[y][x]= d[y,x];
	    // cout << array[y][x] << endl;

	    array[y][rows]=0;
	    array[y][cols-1]=0;
	      if (x==rows)      
           {
      	
	     //  cout << "x :" << x << " i : "<< i << endl;
	     
       	     array[y][x+i]=1;
	     
	     
      	     y=y+1;
	     x=-1;
	     i++;
	     //cout << "i " << i << endl;
         	}
	      // cout << "x " << x << endl;
	      //cout << "y " << y << endl;
	      //cout << "z " << z << endl;
	     
	      //cout << endl;
	     
	      z++;
         }
    ///////////////////////////////////////////////////////////////
       
     
       
      
       
    ///////////////////////////////////////////////////////////////      
        int q=0;
       for (int r=0; r <= (cols) && q <=(rows)-1; r++)
       	{  
	 cout << array[q][r] << " ";
        if (r==cols)
        {
        cout  << endl;
        r=-1;
       	q=q+1;
        }
        }
    }
 return 0;
}
Last edited on
Topic archived. No new replies allowed.