php hit counter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I would able to program in c++ I would be able to program in every language.
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
RESPECTED SIR,your way of teaching is very simple and unique I learnt many things from yours way of teaching

sir i have coded this problem but the result is not good. I want to tranpose the matrix but the

matrix is not transposed please tell me the mistakes and give me the correct code

I would be grateful to you. Sir can you tell me that which language is good for learning

and if I would able to program in c++ I would be able to program in every language.

#include<iostream.h>
#include<conio.h>
const int maxrows=3;
const int maxcols=3;
void readmatrix(int a[][maxcols]);
void displaymatrix(int a[][maxcols]);
void transposematrix(int a[][maxcols]);
main()
{
int a[maxrows][maxcols];
readmatrix(a);
cout<<endl;
cout<<"DISPLAY MATRIX ";
cout<<endl;
displaymatrix(a);
cout<<endl;
cout<<"TRANPOSE THE MATRIX ";
cout<<endl;
displaymatrix(a);
cout<<getch();
}
void readmatrix(int a[maxrows][maxcols])
{
int rows;
int cols;
for (rows=0;rows<maxrows;rows++)
{
for (cols=0;cols<maxcols;cols++)
{
cout<<"PLEASE ENTER THE NUMBER";
cout<<rows;

cout<<cols;
cin>>a[rows][cols];
}
cout<<'\t';
cout<<endl;
}
}

void displaymatrix(int a[][maxcols])
{
int rows;
int cols;
for (rows=0;rows<maxcols;rows++)
{
for (cols=0;cols<maxcols;cols++)
{



cout<<a[rows][cols];
cout<<'\t';
}
cout<<endl;
}
}
void transposematrix(int a[maxrows][maxcols])
{
int rows;
int cols;
int temp;
for (rows=0;rows<maxrows;rows++)
{
for (cols=rows;cols<maxcols;cols++)
{
temp=a[rows][cols];
a[rows][cols]=a[cols][rows];
a[cols][rows]=temp;
}
}
}
Reply
#2
Dear Student,

Below is the corrected modified code of your program.

#include<iostream.h>
#include<conio.h>

const int maxrows=3;
const int maxcols=3;

void readmatrix(int a[][maxcols]);
void displaymatrix(int a[][maxcols]);
void transposematrix(int a[][maxcols]);

main()
{
int a[maxrows][maxcols];

readmatrix(a);

cout<<endl;
cout<<"DISPLAY MATRIX:\n\n";


displaymatrix(a);

cout<<"\nTRANPOSE THE MATRIX ";
cout<<endl;

transposematrix(a);

displaymatrix(a);

cout<<getch();
}


void readmatrix(int a[maxrows][maxcols])
{
int rows;
int cols;

for (rows=0;rows<maxrows;rows++)
{
for (cols=0;cols<maxcols;cols++)
{

cout<<"PLEASE ENTER THE NUMBER FOR ROW "<<rows << " AND COLUMN " <<cols;
cout<<":\t";
cin>>a[rows][cols];

}
}

}

void displaymatrix(int a[][maxcols])
{
int rows;
int cols;

for (rows=0;rows<maxcols;rows++)
{
for (cols=0;cols<maxcols;cols++)
{
cout<<a[rows][cols];
cout<<"\t";
}

cout<<endl;
}
}


void transposematrix(int a[maxrows][maxcols])
{
int rows;
int cols;
int temp;


for (rows=0;rows<maxrows;rows++)
{
for (cols=rows;cols<maxcols;cols++)
{
temp=a[rows][cols];
a[rows][cols]=a[cols][rows];
a[cols][rows]=temp;
}
}

// displaymatrix(a);
}


The problem with you program was that you were not calling transpose function in your main function and also there were some issue with your cout statements.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  c++ program on unix varup 0 7,645 10-10-2012, 06:16 PM
Last Post: varup
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 3,068 05-31-2012, 01:40 AM
Last Post: Vuhelper
  program Output in C++ 2012 Vuhelper 0 3,035 01-06-2012, 12:28 AM
Last Post: Vuhelper
  For running C++ program from command prompt “gcc” and “g++” compilers are used. Vuhelper 0 6,445 01-04-2012, 10:41 PM
Last Post: Vuhelper
  Function (Retrun push)for what purpose use in the program. ? Vuhelper 0 1,913 11-05-2011, 05:03 PM
Last Post: Vuhelper
  Constants in C Language 2011-12 Vuhelper 0 1,806 08-28-2011, 05:35 PM
Last Post: Vuhelper
  C++ Help with Template class program 2011 Vuhelper 0 879 07-23-2011, 05:40 PM
Last Post: Vuhelper
  A simple pthread program runtime error in c++ 2011 Vuhelper 0 959 07-23-2011, 05:39 PM
Last Post: Vuhelper
  Problem with the complexity of the program 2011 Vuhelper 0 798 07-06-2011, 06:19 PM
Last Post: Vuhelper
  Write a calculator program using a do-while loop in c++ 2011 Vuhelper 0 2,823 06-27-2011, 06:41 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support