You are here:   HomeC++ ProgrammingArray Pointer and UnionWrite a C++ program to find average marks of N student each having M subjects in a class.
by Dinesh Thakur Category: Array Pointer and Union

 

#include<iostream.h>
#include<conio.h>
void main()
{
   int i,j,a[10][10],b[10][10],c[10][10],d[10][10],n,m;
   clrscr();
   cout<<"\nEnter the Number of Rows and Columns of Matrix A and B:";
   cin>>n>>m;
   cout<<"\nEnter the Elements of Matrix A: \n";
   for(i=0; i<n;i++)
     {
             for(j=0;j<m;j++)
            {
               cin>>a[i][j];
            }
    }
        cout<<"\nEnter the Elements of Matrix B: \n";
        for(i=0; i<n; i++)
           {
                for(j=0;j<m;j++ )
                   {
                        cin>>b[i][j];
                   }
          }
                        for(i=0; i<n; i++)
                   {
                        for(j=0;j<m ;j++)
                            {
                                   c[i][j]=a[i][j]+b[i][j];
                                   d[i][j]=a[i][j]-b[i][j];
                            }
                  }
                             cout<<"\nThe Resultant Matrix C=A+B is :\n";
                             for(i=0; i<n; i++)
                         {
                              for(j=0; j<m; j++ )
                                 {
                                                       cout<<c[i][j]<<" ";
                                 }
                                       cout<<"\n";
                        }
                                          cout<<"\n The Resultant Matrix D=A-B is : \n";
                              for(i=0; i<n; i++)
                                  {
                                       for (j=0; j<m; j++ )
                                           {
                                                                   cout<<d[i][j]<<" ";
                                                               }
                                               cout<<"\n";
                                 }
                                                getche();
}

Add And Subtract Two Matrices



Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article



Search Content







Advance Courses



Basic Courses



Advertise with Us