-
January 3rd, 2013, 02:17 PM
#1
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....
-
January 3rd, 2013, 03:36 PM
#2
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
-
January 4th, 2013, 06:51 AM
#3
Re: Transpose Matrix array manipulation
Originally Posted by princemoon
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|