Assume the 2D array below has been assigned valid integer values. NUM_PLAYERS and NUM_CARDS are global const ints with positive values. Write a code snippet which computes the total of all the elements in the 2D array.
int cards[NUM_PLAYERS][NUM_CARDS];
#include<bits/stdc++.h>
using namepsace std;
int NUM_PLAYERS = 5;
int NUM_CARDS = 5;
int main()
{
int sum = 0;
int cards[NUM_PLAYERS][NUM_CARDS] = {1};
for(int i=0;i<NUM_players;i++)
{
for(int j=0;j<NUM_CARDS;j++)
{
sum+=cards[i][j];
}
}
cout<<" the total of all the elements in the 2D array is "<<sum<<endl;
}
Get Answers For Free
Most questions answered within 1 hours.