outputting an inputted matrix???

can anyone help me with this??
i am trying to display an inputted 3-D array
here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;

int main()
{
    int k, a[10][11];
    char var = 'a';
    
    cin >> k;
    
    for(int j = 0; j < k; j++)
       for(int i = 0; i < k; i++)
           cin >> a[j][i];   
      
    return 0;
}


here is my input:
3
1 -3 3 -4
2 3 -1 15
4 -3 -1 19


the first input which is 3 is the number of variables, The next lines are the equations specified as an augmented matrix. Each line represents an equation.

the program should output like this
1a + -3b + 3c = -4
2a + 3b + -1c = 15
4a + -3b + -1c = 19
Last edited on
thats not a 3d array, thats a 2d array.

i dont see any output code in the code you posted
here is my first try but it is not correct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
    int k, a[10][11];
    char var = 'a';
    
    cin >> k;
    
    for(int row = 0; row < k; row++)
       for(int column = 0; column < k; column++)
           cin >> a[row][column];   
    
    for(int row = 0; row < k; row++)
       for(int col = 0; col < k; col++)
       {
           if(col == k)
              cout << " = " << a[row][col] << endl;
           if(col == k-1)
              cout << " = " << a[row][col] << endl;
           else
              cout << a[row][col] << var++ << " + ";
       }
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>

int main()
{
    int k, a[10][11];
    char var = 'a';
    
	std::cin >> k;
    
    for(int row = 0; row < k; row++)
       for(int column = 0; column < k; column++)
		   std::cin >> a[row][column];   
    
    for(int row = 0; row < k; row++)
       for(int col = 0; col < k; col++)
       {
           if(col == k)
			   std::cout << " = " << a[row][col] << std::endl;
           if(col == k-1)
			   std::cout << " = " << a[row][col] << std::endl;
           else
			   std::cout << a[row][col] << var++ << " + ";
       }
}
what i mean is every line is a new form of equations..means after the first equation has been outputted, another equation will output and the variables will start again to 'a'.
i dont get it
can you give me an example?
hereis my input:

1 -3 3 -4
2 3 -1 15
4 -3 -1 19


this should be the output:

1
2
3
4
1a + -3b + 3c = -4    // 1st equation
2a + 3b + -1c = 15    // 2nd equation
4a + -3b + -1c = 19   // 3rd equation
                   //*** take a look at the variables 
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
#include<iostream>

int main()
{
    int k, a[10][11];
    
	std::cin >> k;
    
    for(int row = 0; row < k; ++row)
       for(int column = 0; column < k; ++column)
		   std::cin >> a[row][column];   
    
    for(int row = 0; row < k; row++)
	{
    char var = 'a';
		for(int col = 0; col < k; col++)
		{
			if(col == k)
				std::cout << " = " << a[row][col] << std::endl;
			if(col == k-1)
				std::cout << " = " << a[row][col] << std::endl;
			else
				std::cout << a[row][col] << var++ << " + ";
		}
	}
}
the output is not correct but maybe i can get some ideas in your code...
thank you sir for helping me.. :)
Topic archived. No new replies allowed.