Code Competitions

Coding competition

Monday, 3 June 2013

program to find the sum of rows and column of matrix

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
    int i,j,m,n,a[10][10]={0},b[10]={0},c[10]={0};
    clrscr();
    cout<<"\nenter the order of matrix ";
    cin>>m>>n;
    cout<<"\nenter the elements :";
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            b[i]+=a[i][j];
            c[j]+=a[i][j];

        }
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            cout.width(8);
            cout<<a[i][j];
        }
        cout.width(8);
        cout<<"  "<<b[i];
        cout<<"\n";
    }
    cout<<"\n";
    for(i=0;i<n;i++)
    {
        cout.width(8);
        cout<<c[i];
    }
    getch();
}

No comments:

Post a Comment