WAP for row sum and col sum
#include<iostream>
#define max 100
using namespace std;
int main()
{
    int a[max][max],row,col,sum = 0;;
    cout<<“Enter the row of matrix : “;
    cin>>row;
    cout<<“Enter the col of matrix : “;
    cin>>col;
    //input matrix
    for(int i = 0 ;i < row ; i++)
    {
        for(int j = 0 ; j < col  ; j++)
        {
            cout<<“Enter the element at index [“<<i<<“][“<<j<<“] : “;
            cin>>a[i][j];
        }
    }
    //print matrix
    for(int i = 0 ;i < row ; i++)
    {
        for(int j = 0 ; j < col  ; j++)
        {
           
            cout<<a[i][j] << ” “;
        }
        cout<<endl;
    }
    //row sum
    for(int i = 0 ;i < row ; i++)
    {
        for(int j = 0 ; j < col  ; j++)
        {
           
           sum = sum + a[i][j];
        }
        cout<<“Sum of row “<<i+1<< ” is “<<sum;
        sum = 0;
        cout<<endl;
    }

    //col sum
    for(int i = 0 ;i < row ; i++)
    {
        for(int j = 0 ; j < col  ; j++)
        {
           
           sum = sum + a[j][i];
        }
        cout<<“Sum of col “<<i+1<< ” is “<<sum;
        sum = 0;
        cout<<endl;
    }

    return 0;
}
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare