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

Wednesday, February 10, 2010

Write a program to enter elements of any square matrix. Then create another matrix which will store the double of each element of the previous matrix. Then print all the elements of the second matrix in row and column format.


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


void main()
{
int mat[10][10],  n;


cout<< "\n Enter dimension of the square matrix :";
cin>> n;


/*  .. Input Matrix ..*/
for(int i =0 ; i< n ; i++ )
for ( int j = 0 ; j< n ; j++)
{
cout<< "\n Enter an element for position " << i+1 << " , " <<  j+1 << ": " ;
cin >> mat[i][j];
}


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


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


cout<<"\n The original matrix :";
for( i =0 ; i< n ; i++ )
{
for( j =  0 ; j< n ; j++)
cout<< mat[i][j] << "  ";
cout << "\n";
}


cout<<"\n The Output Matrix : "
for(i =0 ; i< n ; i++ )


{for(j=0; j< n ; j++)
cout<< mat[i][j] << "  ";
cout<< "\n" ;
}


getch();
}

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.