"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Saturday, February 20, 2010

Write a C++ program to use the following function :

(i) display() to display a matrix of a size m x n.
(ii) times2() to double each number of the matrix of size mxn.
(iii) main() to read a matrix of size mxn and then to display original matrix and then to display the new matrix formed by doubling its elements.

void display(int a[][], int m, int n)
for(int i = 0; i< m ; i++)
  for( int j = 0; j< n ; j++)
        cout << a[i][j] << "  ";
   cout<< endl;

void times2(int a[][], int m, int n)
for(int i = 0; i< m ; i++)

  for( int j = 0; j< n ; j++)
     a[i][j] = a[i][j] * 2;


void main()
int mat[10][10], row, col, i, j;

cout<< "\n Enter total rows :";
cin>> row;

cout<<" \n Enter total columns :";
cin>> col;

cout<< "\n Enter the elements for Matrix:";

for(i = 0; i< row; i++)

  for(j = 0; j< col; j++)

cout<<"\n The Original Matrix :";
display(mat, row, col);

times2(mat, row, col);

cout<<"\n The New Matrix :";

display(mat, row, col);


No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.