Showing Page:
1/2
bool isAllZeros(int a[50][100]);
Implement the function isAllZeros that uses a loop nested
inside another loop to determine
whether a 2-dimensional array contains only zeros. A
declaration of the function is shown above.
The array passed into the function will have 50 rows and
100 columns.
Write test code that thoroughly tests the function. The test
code should use assertions.
Solution
#include <iostream>
#include <cassert>
using namespace std;
bool isAllZeros(int a[50][100]);
int main()
{
int a[50][100];
for(int i=0;i<50;i++) {
for(int j=0;j<100;j++){
a[i][j]=0;
}
Showing Page:
2/2
}
assert (isAllZeros(a) == true);
a[0][0]=1;
assert (isAllZeros(a) == false);
return 0;
}
bool isAllZeros(int a[50][100]) {
for(int i=0;i<50;i++) {
for(int j=0;j<100;j++){
if(a[i][j]!=0){
return false;
}
}
}
return true;
}

Unformatted Attachment Preview

Name: Description: ...
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4