C++ program to enter 3 x 3 matrix

      No Comments on C++ program to enter 3 x 3 matrix

Enter 3 x 3 matrix

C++ program to enter 3 x 3 matrix.Here “a[3][3]” is the name of array with 3 rows and 3 coloumns .In for loop i is the number of rows and j is the number of coloumns.

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
int a[3][3],i,j;
 cout<<"Enter Matrix row wise:-\n";

 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     cin>>a[i][j];
    }
  }
  cout<<"Entered Matrix is:-\n";
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     cout<<"\t"<<a[i][j];

    }
    cout<<"\n";
  }
 getch();
}

OUTPUT

 enter 3 x 3 matrix


Using concept of class

#include<iostream.h>
#include<conio.h>
class scan
{
 private:
 int d1,d2,p[10][10],i,j;
 public:
 void get(int x,int y)
  {
   d1=x;
   d2=y;
  }
 void get_ele(int i,int j,int val)
 {
  p[i][j]=val;
 }
 void show();
} ;

void scan::show()
{
  cout<<"Entered matrix is:- "<<endl;
  for(i=0;i<d1;i++)
   {
    for(j=0;j<d2;j++)
     {
      cout<<"\t"<<p[i][j];
     }
     cout<<endl;
   }
}

void main()
{
 clrscr();
 scan s1;
 int a,b,m,i,j;
 cout<<"Enter number of rows in matrix:- "<<endl;
 cin>>a;
 cout<<"Enter number of coloumns in matrix:- "<<endl;
 cin>>b;
 s1.get(a,b);
 cout<<"Enter matrix row wise"<<endl;
 for(i=0;i<a;i++)
  {
   for(j=0;j<b;j++)
    {
     cin>>m;
     s1.get_ele(i,j,m);
    }
  }
  s1.show();
 getch();
}

OUTPUT

Enter 3 x 3 matrix


What is matrix

  • It is a rectangular array arranged in rows and coloumns.
  • Suppose a matrix “A” is denoted by m x n order.Where m=rows and n=coloumns.
  • Individual item in matrix “A” will be denoted by “aij” where i=m and j=n.

  • Comment below if you are facing any problem.


    Also read

    C program of 2D array to enter matrice
    C program to multiply two matrix
    C++ program of defining array

    Summary
    C++ simple program to enter 3 x 3 matrix
    Article Name
    C++ simple program to enter 3 x 3 matrix
    Description
    This program illustrate the concept to enter 3 x 3 matrix in c++.Matrix is a rectangular array arranged in rows and coloumns.
    Author
    Publisher Name
    Scanfcode
    Publisher Logo

    Leave a Reply

    Your email address will not be published. Required fields are marked *