+ 2
problem in adding two dimensional array.
#include <iostream> using namespace std; int main(){ long long int n,m; cin>>n>>m; long long int arr[n][m]; for(unsigned i=0;i<n;i++){ for(unsigned j=0;j<m;j++){ cin>>arr[i][j]; } } int sum=0; for(unsigned j=0;j<m;j++){ for(unsigned i=0;i<n;i++){ sum+=arr[i][j]; } cout<<sum<<" "; sum=0; } return 0; } for input like: 5 6 4 5 0 7 7 0 6 4 6 2 1 4 2 0 3 9 0 1 0 5 6 9 8 1 4 7 9 8 8 9 the correct output is: 16 21 24 35 24 15 and it is correct but test case three is failing as wrong answer. The program only has to add elements column vise and print the output.
2 Respostas
+ 4
it worked I got it, only I had to make the data type of sum = long long int..
IN between writing the question