Write a function called isIthRowExactlyZero that takes a 2D array of real number
ID: 1828953 • Letter: W
Question
Write a function called isIthRowExactlyZero that takes a 2D array of real numbers, called M, and returns true if *all* the elements in the ith row are 0.0, and false if not. M has numRows rows and numCols columns, which are parameters along with M and i. NOTE: the value of i passed to the function is between 1 and R, inclusive. For example, if the caller wants to know if the first row of M is all zero, then i will have the value 1, not 0.
Instructor's notes: Hint: think of this like a search, where you are searching for a value that is not 0.0.
bool isIthRowExactlyZero(int i, double M[MAXROWS][MAXCOLS], int numRows, int numCols)
{
}
Explanation / Answer
bool isIthRowExactlyZero(int i, double M[MAXROWS][MAXCOLS], int numRows, int numCols)
{
int row = i-1;
bool flag = true;
for(int x=0; x<numCols; x++)
{
if M[row][x]!=0.0
{
flag = false;
break;
}
}
return flag;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.