Transpose Matrix array manipulation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Transpose Matrix array manipulation

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Smile Transpose Matrix array manipulation

    Hi guys I am working on this program
    Array Manipulation - Transpose of a Square Matrix: This program reads a matrix (two dimensional array), displays its contents, transposes it and then displays the transposed matrix.
    and here's the code
    Code:
    #include <iostream.h>
    
    const int arraySize = 3;
    
    void readMatrix(int arr[][arraySize]);
    void displayMatrix(int a[][arraySize]);
    void transposeMatrix(int a[][arraySize]);
    
    void main(void)
    {
    
    int a[arraySize][arraySize]; 
    
    readMatrix(a); //Read the matric element int the array
    
    cout<<"\n\n"<<"The original matrix is:"<<'\n'; //Display the matrix
    
    displayMatrix(a);
    
    transposeMatrix(a); //transpose the matrix
    
    cout<<"\n\n"<<"The transposed matrix is:" << '\n'; //Display the transposed matrix
    displayMatrix(a);
    }
    
    void readMatrix(int arr[][arraySize])
    {
         int row, col;
         
         for(row = 0; row<arraySize;row++)
         {
                 for(col=0; col<arraySize; col++)
                 {
                            cout<<"\n"<<"Enter"<<row<<","<<col<<"element";
                            cin>>arr[row][col];
                            }
                            cout<<'\n';
                            }
                            }
                 void displayMatrix(int a[][arraySize])
                 {
                      int row,col;
                      for (row=0; row<arraySize;row++)
                      {
                          for(col=0; col<arraySize; col++)
                          {
                                     cout<<a[row][col]<<'\t';
                                     }
                                     cout<<'\n';
                                     }
                                     }
                           void trnasposeMatrix(int a[][arraySize])
                           {
                                int row,col;
                                int temp;
                                for(row=0; row < arraySize; row++)
                                {
                                for(col=row; col<arraySize;col++)
                                {
                                temp=a[row][col]; //save the original value in the temp variable
                                a[row][col]=a[col][row];
                                a[col][row]=temp; //take out the original value
                                }
                                }
                                }
    When I compile the program it says 'mail' must return 'int' I think everything is right please help me on this....

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Transpose Matrix array manipulation

    The compiler is correct. "main" must return an integer:
    Code:
    #include <iostream>
    
    int main()
    {
       std::cout << "Hello World!" << std::endl;
    }
    However, you do not need to provide the return value (IIRC, the default is 0, but I could be wrong).

    Viggy

  3. #3
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Transpose Matrix array manipulation

    Quote Originally Posted by princemoon View Post
    I think everything is right please help me on this....
    Code:
    #include <iostream.h>
    What compiler are you using? There is no such header as <iostream.h> in ANSI C++.

    Correction:
    Code:
    #include <iostream>
    The standard header is <iostream>, not <iostream.h>. If you're reading a book that uses <iostream.h> get a newer or different book. If you're using code gotten from a website with <iostream.h>, go to a better or newer website. If you are being taught <iostream.h> by a teacher, get a new teacher.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center