Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 14-01-2008, 02:42 AM   #1 (permalink)
Alpha Geek
 
The Incredible's Avatar
 
Join Date: May 2005
Location: Planet Incredible
Posts: 579
Default Incredible Input Incredible Output (ProgLang-C++)(Comp-TC++)


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

Code:
//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();
}
Code:
//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 ??
The Incredible is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 16-01-2008, 12:44 PM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Incredible Input Incredible Output (ProgLang-C++)(Comp-TC++)

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

Input:
Code:
01 02 03 04

05 06 07 08

00 00 00 00
Output (Reverse):
Code:
 0  0  0  0 

 8  7  6  5 

 4  3  2  1
Output (Transpose):
Code:
  1   5   0 

  2   6   0 

  3   7   0 

  4   8   0
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 20-01-2008, 06:47 PM   #3 (permalink)
Alpha Geek
 
The Incredible's Avatar
 
Join Date: May 2005
Location: Planet Incredible
Posts: 579
Default Re: Incredible Input Incredible Output (ProgLang-C++)(Comp-TC++)

So, just because of the use of char(i,j) set, the results are altering ?
The Incredible is offline  
Old 20-01-2008, 07:55 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Incredible Input Incredible Output (ProgLang-C++)(Comp-TC++)

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:
Code:
//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(char i=0;i<4;++i)
   {
   for(char j=0;j<3;++j)
      cout<<setw(3)<<a[j][i]<<" ";
   cout<<endl;
   }
}
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching 3 incredible sites [Feb 2005 issue] keves2002 QnA (read only) 3 17-10-2006 01:57 PM
KGB Archiver, incredible.....my god!!! rajat22 QnA (read only) 28 16-04-2006 11:09 PM
output video from comp 2 tv along with scrolling text(urgnt) manmay Software Q&A 3 26-01-2006 06:07 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2