Question

Write while loop code (you cannot use for, although nested while loops are ok), which searches...

Write while loop code (you cannot use for, although nested while loops are ok), which searches a two-dimensional int array ArrTwo to find ALL elements that are equal to zero (0), and print both indexes (row, column) of each zero once it is found.   If there are no zeroes in the array, the code should print “Zero not found”.   Each index pair (row,col) should be printed only once.    * Note: This question is NOT asking you to write a method.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:-

#include <iostream>
using namespace std;

int main() {
   int m,n,i=0,j=0,count=0;
   cout<<"enter the row and column : ";
   cin>>m>>n;
   int arr[m][n];
   cout<<"enter the array elements : ";
   while(i<m)
   {
       j=0;
       while(j<n)
       {
           cin>>arr[i][j];
           j++;
       }
       i++;
   }
   i=0;
   j=0;
   while(i<m)
   {
       j=0;
       while(j<n)
       {
           if(arr[i][j]==0)
           {
           cout<<"("<<i<<","<<j<<")"<<endl;
           count++;
           }
           j++;
       }
       i++;
   }
   if(count==0)
   cout<<"Zero not found.";
   return 0;
}

// OUTPUT

// If any doubt please comment

Add a comment
Know the answer?
Add Answer to:
Write while loop code (you cannot use for, although nested while loops are ok), which searches...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT