Friday, 18 January 2013

2D Matrix Addition,Maltiplication,subtracion and all basic operation

       /*Two dimension Arrays **/
       /*__________________________________________________________*/
       /*These are the header files*/
  #include <iostream>/*Use for input/output stream operator like cout<<,cin>> stream means flow of data
                     when we use input stream it means data flow from input devices like key borad ,mouse etc,....and when use out it means
                     data flow frow output devices like printer ,monitor,...etc */
  #include <conio> /*Use for controll getch() function which is use to hold flashing the screen*/
  #include <stdlib> /*here it use for control the exit function*/

             int arr[8][8],a,b,i,j,opt;  /*here two di_menension array and a,b,i,j,opt are  declare whih have integer data_type*/

            int ar[8][8];/*here also two di_nenension Array is declare which have interger data_type*/
        void main()  /*here main function is defined*/

        {


           cout<<"Enter Row for Ist Matrix\t";
           cin>>a;
                                    cout<<endl;
           cout<<"Enter COloum for Ist Matrix\t";
           cin>>b;

           if(a==b)
           {


             cout<<"Enter element for ist matrix\n";
             for(i=0;i<a;i++)

             {
              for(j=0;j<b;j++)

              {
               cin>>arr[i][j];
              }
             }

             cout<<"Your desire Matrix is A=\t";


             for(i=0;i<a;i++)
             {
              for(j=0;j<b;j++)

              {
               cout<<arr[i][j]<<"  ";
              }

              cout<<endl;
              cout<<"\t\t\t\t";

             }
                 cout<<endl<<endl;


           }
           else
          { cout<<"Order of matrix is not same\n";  }





           cout<<"Enter Row for 2nd Matrix\t";
           cin>>a;
                                    cout<<endl;
           cout<<"Enter COloum for 2nd Matrix\t";
           cin>>b;

           if(a==b)
           {
             cout<<"Enter element for 2nd matrix\n";
             for(i=0;i<a;i++)

             {
              for(j=0;j<b;j++)

              {
               cin>>ar[i][j];
              }
             }

             cout<<"Your desire Matrix isB=\t\t";

             for(i=0;i<a;i++)
             {
              for(j=0;j<b;j++)

              {
               cout<<ar[i][j]<<"  ";
              }
              cout<<endl;
               cout<<"\t\t\t\t";
             }

               cout<<endl<<endl;
           }
           else
           {cout<<"Order of matrix is not same\n";}

           cout<<"\n\n\n";
           while(1)                                 /*Using while loop make a Program menue */

           { cout<<"\n\n\n";
             cout<<"\t\tWEL_COME _TO _THE _MAIN _MENU \n";
             cout<<endl;
             cout<<"\t\tENTER 1 FOR MATRIX MULTIPLICATION\n";
             cout<<"\t\tENTER 2 FOR MATRIX ADDITON\n";
             cout<<"\t\tENTER 3 FOR MATRIX SUBTRACTION\n";
             cout<<"\t\tENTER 4 FOR TRANSPOSE OF A\n";
             cout<<"\t\tENTER 5 FOR TRANSPOSE OF B\n";
             cout<<"\t\tENTER 6 FOR CLEAR SCREEN\n";
             cout<<"\t\tENTER 7 FOR EXIT FROM THE PROGRAM\n";


             cin>>opt;

             switch(opt)
             {



          case 1:                  /*for Multiplication*/
           int pro[8][8];

           for(i=0;i<a;i++)
           {
           for(j=0;j<b;j++)
           {
           pro[i][j]=0;

            for(int k=0;k<a;k++)
            {
             pro[i][j]+=arr[i][k]*ar[k][j];
            }
           }
           }

             cout<<"The Multiplication of AXB=\t";
  for(i=0; i<a; i++)
  {
  for(j=0; j<b; j++)
  cout<<pro[i][j]<<"\t";
  cout<<endl;
  cout<<"\t\t\t\t";
  }
   break;

   case 2:               /*For Addition*/

   {
 int sum[8][8];
 cout<<"The Additon of A+B=\t";
 for(i=0;i<a;i++)
 {
 for(j=0;j<b;j++)
 {sum[i][j]=arr[i][j]+ar[i][j];
 }  }
 for(i=0;i<a;i++)
 {
 for(j=0;j<b;j++)
 {cout<<sum[i][j]<<"\t";
 }

 cout<<endl;
 cout<<"\t\t\t";}break;
 }
 case 3:
  {
                                       /*For Subtraction*/
 int sub[8][8];
 cout<<"The subtraction of A-B=\t";
 for(i=0;i<a;i++)
 {
 for(j=0;j<b;j++)
 {sub[i][j]=arr[i][j]-ar[i][j];
 }  }
 for(i=0;i<a;i++)
 {
 for(j=0;j<b;j++)
 {cout<<sub[i][j]<<"    ";
 }
 cout<<endl;
 cout<<"\t\t\t";}
  break;
 }                     /*For Transpose of Matrix_ A*/
 case 4:
 {
 cout<<"The Tranpose of  A is=\t";
  for(i=0;i<a;i++)
 {
 for(j=0;j<b;j++)
 {
 cout<<arr[j][i]<<"  ";
 }
cout<<endl;
cout<<"\t\t\t"; }
 break;  }
 case 5:
 {
 cout<<"The Tranpose of  B is=\t";
  for(i=0;i<a;i++)                     /*For Transpose of Matrix_B*/
 {
 for(j=0;j<b;j++)
 {
 cout<<ar[j][i]<<"  ";
 }
cout<<endl;
cout<<"\t\t\t"; }
 break;  }
 case 6:          /*For clear screen*/
 clrscr();
 break;
 case 7:
 exit(0);      /*For exit program*/
 break;
 default:
 cout<<"\t Are You balaned if  you not then chiose correct option\n";
 break;

    }}
     getch();}       /*End of Main function*/


     /*Best of luck*/    

1 comment: