67 245
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #47691 in C++ for rishi

Question #47691
write a COLSUM() function in c++ to find sum of each column o a N*M Matrix.
Expert's answer
#include <stdlib.h>
#include <iostream>  
#include <stdio.h>
#include <cstdlib>  
using namespace std;
void ColSum(int **mas, int n, int m);
int main()
{
int n,m;
cout<<"Enter the n: ";
cin>>n;
cout<<"Enter the m: ";
cin>>m;
int  **mas = new int* [n];
for (int i = 0; i < n; i++)
mas[i] = new int[m];
cout<<"Enter the array elements: (Array "<<n<<"*"<<m<<"):"<<endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin>>mas[i][j];
}
}
ColSum(mas, n, m);
system("pause");
return 0;
}
void ColSum(int* mas[], int n, int m)
{
int sum = 0;

for (int j = 0; j < m; j++)
{
for (int i = 0; i < n;i++)
{
sum +=mas[i][j];
}
cout<<"Sum of "<<j+1<<" column: "<<sum<<endl;
sum = 0;

}
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions