How to display a message and numbers not present into a matrix
-
Hi Zlatko, What I really want is a display like this: ROWS (0) (1) (2) (3) (4) ----------------------------------------------------- 0) 1 13 23 45 50 1) 5 12 34 36 51 2) 2 23 25 46 54 3) 2 7 35 39 48 4) 34 5 26 39 49 Enter the number you are searching for in column (0): 2 NUMBER 2 in COLUMN (0) in 5 ROWS ROWS (0) (1) (2) (3) (4) ----------------------------------------------------- 2) 2 23 25 46 54 3) 2 7 35 39 48 Enter the number one (1): 1 NUMBERS THAT ARE NOT IN THE MATRIX BETWEEN THE NUMBERS 1 AND 56 1 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 26 27 28 29 30 31 32 33 34 36 37 38 40 41 42 43 44 45 47 49 50 51 52 53 55 56 If you see, I displayed all the numbers between 1 and 56 not present in the following matrix: NUMBER 2 in COLUMN (0) in 5 ROWS ROWS (0) (1) (2) (3) (4) ----------------------------------------------------- 2) 2 23 25 46 54 3) 2 7 35 39 48 This is the code I used to get that: if (foundInFirstCol) { cout >Number; cout cout do{ bool foundInMatrix = false; for(int i=0; i Hi Zlatko What I want from the following program is to get the rows with a desired number in column (0) and if this number is not in column (0), then display a message (This number is not found in column (0)) and after that, obtain the numbers not presents in the whole matrix between 1 and 56 that I got when I entered a desired number. I could create the code for the first part but I do not know how to display a message if the number is not in column (0), besides, I do not know how to obtain the numbers not presents in the whole matrix that I got when I entered a desired number. Could you help me. Thanks. This is what I got so far: int rows=5; int columns=5; int minWishedNumber=1; int maxWishedNumber=56; int wishedNumber; using namespace std; int getWishedNumber(); void displayRows(int array[], int index); void printHeading(); int main() { cout printHeading(); for(int i=0; i { cout " printHeading(); cout for(int i=0; i { for(int j=0; j cout > choice; } while (choice == 'y'|| choice == 'Y'); cout } int getWishedNumber() { cout > wishedNumber; while (wishedNumber maxWishedNumber) { cout minWishedNumber; cout > wishedNumber; cout return wishedNumber; } void displayRows(int array[], int index) { for( int i=0; i cout } cout } void printHeading() { cout cout }
-
Answer:
Hello Raul. I think I understand your question now. Step 1) The program asks for a number. Then it returns all the rows that have that number in column 0. Step 2) The program prints out all numbers between 1 and 56 which are not in the rows returned in step 1. A simple and efficient way of doing this is to make an array of 57 integers. Go through the rows returned from step 1, and for each number (i), set array[i] = 1. In the end, if element i is not 0, it means that i is in the matrix. Then go through the array and print out all i where array[i] is 0. The code below does it. I hope it is clear enough. int rows=5; int columns=5; int minWishedNumber=1; int maxWishedNumber=56; int wishedNumber; using namespace std; int getWishedNumber(); void displayRows(int array[], int index); void printHeading(); int main() { cout printHeading(); for(int i=0; i /* The foundList will record which numbers are in the matrix. If foundList[i] is not 0, it means that i is in the matrix. */ int foundList[57]; memset(foundList, 0, sizeof(foundList)); bool foundInFirstCol = false; /* Check if the wished number is in the first column */ for(int i=0; i if (foundInFirstCol) { /* Print out the elements not in the foundList */ cout cout > choice; } while (choice == 'y'|| choice == 'Y'); cout } int getWishedNumber() { cout > wishedNumber; while (wishedNumber maxWishedNumber) { cout > wishedNumber; cout } void displayRows(int array[], int index) { for( int i=0; i } void printHeading() { cout } Hello Raul, I had a little trouble understanding what you want, but I think you want to display if a number is in the first column, and if not, then go on to check if it is in the rest of the matrix. Below is the code for that. Between the lines /* BEGIN addition to code */ and /* END addition to code */ is code that I added. I think you should be able to understand it. Let me know if you need more help. int rows=5; int columns=5; int minWishedNumber=1; int maxWishedNumber=56; int wishedNumber; using namespace std; int getWishedNumber(); void displayRows(int array[], int index); void printHeading(); int main() { cout printHeading(); for(int i=0; i /* Check if the wished number is in the first column */ bool foundInFirstCol = false; // ZM added this for(int i=0; i /* BEGIN addition to code */ /* if the number is not in the first column, see if it is in the rest of the matrix */ if (! foundInFirstCol) { cout /* END addition to code */ cout > choice; } while (choice == 'y'|| choice == 'Y'); cout } int getWishedNumber() { cout > wishedNumber; while (wishedNumber maxWishedNumber) { cout > wishedNumber; cout } void displayRows(int array[], int index) { for( int i=0; i } void printHeading() { cout }
Miningco.com Visit the source
Related Q & A:
- How to fire a function before and after automatically in a jquery plugin?Best solution by catchmyfame.com
- How to receive a message from server?Best solution by Code Review
- How long can a Canadian stay in the US for a vacation?Best solution by forbes.com
- How to make a cover letter if you apply as a dental assistant?Best solution by coverletter.us
- HOW TO SAVE A MESSAGE?Best solution by Super User
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.