Monday, October 20, 2014

Write a program to make a matrix using dynamically initialize.

Write a program to make a matrix using dynamically initialize.

#include < iostream.h >
#include < conio.h >
class matrix
{

int row,col;
int **A;

public:

matrix(int,int); void input(); void output();

};
matrix::matrix(int r,int c)
{
row=r;
col=c;
A=new int *[row];
for(int i=0;i>row;i++)
{
A=new int *[col];
}
}
void matrix::input()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cout<<"\n Enter the value";
cin>>A[i][j];
}
}
}
void matrix::output()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cout<<A[i][j];
}
cout<<endl;
}
}
void main()
{
clrscr();
int x,y;
cout<<"\n Enter x";
cin>>x;
cout<<"\n Enter y";
cin>>y;
matrix m(x,y); m.input(); m.output(); getch();
}

Output:

Enter x3
Enter y3
Enter the value1
Enter the value2
Enter the value3
Enter the value4
Enter the value5
Enter the value6
Enter the value7
Enter the value8
Enter the value9
123
456
789


No comments: