Like Tree5Likes
  • 4 Post By Salem
  • 1 Post By Vespasian

problem in Program to find Transpose of Given Square Matrix

This is a discussion on problem in Program to find Transpose of Given Square Matrix within the C++ Programming forums, part of the General Programming Boards category; hi .I want to find transpos of square matrix.but my program does not run complete.I think there is some problem.can ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Location
    iran
    Posts
    2

    problem in Program to find Transpose of Given Square Matrix

    hi .I want to find transpos of square matrix.but my program does not run complete.I think there is some problem.can you help me?
    Code:
    
    
    #include<iostream>
    using namespace std;
    const int size=3;                          
    void read(int a[size][size])
    {
    cout<<"enter"<<size*size<<numbers<<endl;                                 for(int i=0;i<size;i++){
    cout<< "row"<<i<<":";
    for(int j=0;j<size;j++)
    cin>>a[i][j];
    }}
    void trans(int at[size][size],int a[size][size])
    {
    int i,j;
    for(int i=0;i<size;i++){
    for(int j=0;j<size;j++)
    at[i][j]=a[j][i];
    cout<<at[i][j];
    cout<<endl;
    }}
    int main()
    {
    int a[3][3],at[3][3];
    read(a);
    trans(a,at);
    trans(a,at);
    return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    First, indent your code so that it is readable.
    http://sourceforge.net/apps/mediawik...le=Indentation
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Vespasian's Avatar
    Join Date
    Aug 2011
    Posts
    181
    Quote Originally Posted by nazanin.padekan View Post
    hi .I want to find transpos of square matrix.but my program does not run complete.I think there is some problem.can you help me?
    Code:
    
    
    #include<iostream>
    using namespace std;
    const int size=3;                          
    void read(int a[size][size])
    {
    cout<<"enter"<<size*size<<numbers<<endl;                                 for(int i=0;i<size;i++){
    cout<< "row"<<i<<":";
    for(int j=0;j<size;j++)
    cin>>a[i][j];
    }}
    void trans(int at[size][size],int a[size][size])
    {
    int i,j;
    for(int i=0;i<size;i++){
    for(int j=0;j<size;j++)
    at[i][j]=a[j][i];
    cout<<at[i][j];
    cout<<endl;
    }}
    int main()
    {
    int a[3][3],at[3][3];
    read(a);
    trans(a,at);
    trans(a,at);
    return 0;
    }
    It seems you tried to add "numbers" as a string literal but accidentally added it in as a variable with no initialisation and hence the compiler complains.

    I think what you tried to do was the following; it works now; but this time it doesnt do what you want it to do:

    Code:
    #include<iostream>
    using namespace std;
    const int size=3;
    
    void read(int a[size][size])
    {
        cout<<"enter"<<size*size<<" numbers"<<endl;
        for(int i=0;i<size;i++){
            cout<< "row"<<i<<":";
            for(int j=0;j<size;j++)
            cin>>a[i][j];
        }
    }
    
    void trans(int at[size][size],int a[size][size])
    {
        int i,j;
        for(int i=0;i<size;i++){
            for(int j=0;j<size;j++)
                at[i][j]=a[j][i];
            cout<<at[i][j];
            cout<<endl;
        }
    }
    
    
    int main()
    {
        int a[3][3],at[3][3];
        read(a);
        trans(a,at);
        //trans(a,at);
        return 0;
    }
    stahta01 likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matrix Transpose
    By onako in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2010, 05:47 AM
  2. Replies: 4
    Last Post: 05-25-2009, 09:29 PM
  3. transpose matrix
    By nynicue in forum C Programming
    Replies: 4
    Last Post: 12-27-2008, 06:50 PM
  4. Help with matrix transpose
    By sass208 in forum C Programming
    Replies: 6
    Last Post: 12-09-2006, 01:02 AM
  5. transpose matrix?
    By tmoney$ in forum C Programming
    Replies: 4
    Last Post: 05-03-2003, 03:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21