(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.
{
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++)
cin>>mat[i][j];
cout<<"\n The Original Matrix :";
display(mat, row, col);
times2(mat, row, col);
cout<<"\n The New Matrix :";
display(mat, row, col);
getch();
}
(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.
#include <iostream.h>
#include <conio.h>
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++)
cin>>mat[i][j];
cout<<"\n The Original Matrix :";
display(mat, row, col);
times2(mat, row, col);
cout<<"\n The New Matrix :";
display(mat, row, col);
getch();
}
No comments:
Post a Comment