# Incredible Input Incredible Output (ProgLang-C++)(Comp-TC++)



## The Incredible (Jan 14, 2008)

Here're two progs to transpose and mxn matrix and reverse the same.


```
//TO REVERSE A 3X4 MATRIX.//
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int a[3][4];
for(char i=0;i<3;++i)
   {
   for(char j=0;j<4;++j)
      cin>>a[i][j];
   }
for(i=2;i>=0;--i)
   {
   for(char j=3;j>=0;--j)
      cout<<setw(2)<<a[i][j]<<" ";
   cout<<endl;
   }
getch();
}
```


```
//TO TRANSPOSE A MXN MATRIX.//
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int a[3][4];
cout<<"ENTER THE ELEMENTS OF ARRAY : ";
for(char i=0;i<3;++i)
   {
   for(char j=0;j<4;++j)
      cin>>a[i][j];
   }
for(i=0;i<4;++i)
   {
   for(char j=0;j<3;++j)
      cout<<setw(3)<<a[j][i]<<" ";
   cout<<endl;
   }
getch();
}
```

Give the Input :
01 02 03 04
05 06 07 08
00 00 00 00

You'll get the Output :
Case I:
00 00 00 08
00 07 06 05
04 03 02 01
Case II:
01 05 08 
02 06 00
03 07 00
04 00 00

What is making the output go wrong ??


----------



## QwertyManiac (Jan 16, 2008)

Am getting both right, but using a normal int counter set (i,j) rather than a char one.

Input:

```
01 02 03 04

05 06 07 08

00 00 00 00
```
Output (Reverse):

```
0  0  0  0 

 8  7  6  5 

 4  3  2  1
```
Output (Transpose):

```
1   5   0 

  2   6   0 

  3   7   0 

  4   8   0
```


----------



## The Incredible (Jan 20, 2008)

So, just because of the use of char(i,j) set, the results are altering ?


----------



## QwertyManiac (Jan 20, 2008)

Just tried it with char (i,j) too, but it does the same thing, my output is all right.

Maybe you need to add char to both the counter usage parts, like ISO C++ demands?

Like this:

```
//TO TRANSPOSE A MXN MATRIX.//
#include<iostream>
#include<iomanip>

using namespace std;

main()
{
int a[3][4];
cout<<"ENTER THE ELEMENTS OF ARRAY : ";
for(char i=0;i<3;++i)
   {
   for(char j=0;j<4;++j)
      cin>>a[i][j];
   }
for([B]char[/B] i=0;i<4;++i)
   {
   for([B]char[/B] j=0;j<3;++j)
      cout<<setw(3)<<a[j][i]<<" ";
   cout<<endl;
   }
}
```


----------

