C :: Scanning 2 Dimensional Array For Duplicate Values
Mar 26, 2013
I am trying to scan a 2 dimensional array to see if there are any duplicates within a row or column; i.e. the concept of a sudoku game.how to scan a row or column one at a time.
I have an algorithm which uses nested for loops, which looks for duplicate elements in an array. However, as soon as one duplicate element is found... the program will stop looking for more duplicates? My program continues to look for more even though one is found? I know there is a break command but I can't get it to work. Code is below:
output of program: Repeating element found first was: 2, 1
Although I want the outcome to be; Repeating element found first was: 2
#include<stdio.h> #include<stdlib.h> #include <iostream> using namespace std; void printRepeating(int arr[], int size) { int i, j;
I'm trying to write a very simple program that takes values in through variables, and stores those values in a two dimensional array. The values are already passed into the void function, I need to have those values write to their corresponding locations in the array.
void planeSeats(int seats[13][6], int ticket, int ticketRow, int ticketColumn) { if (ticket = 1) { if (ticketRow >= 1 && ticketRow <= 2) {
[Code] ....
For example, lets say that ticketrow is 2 and ticket Column is 4 .
What I need is for ticketRow and ticketColumn to assign that data to seat[ticketRow][ticketColumn], turning it into seat[2][4]. How to do that.
I'm okay with 2-dimensional arrays, but when I get to 3 or more, I can't seem to wrap my head around how to assign and/or pull values from specific parts.
To give an example, let's take the following example:
We know that a player can take up to 5 total quests, and each quest can have a max of 5 tasks.
Let's assume I have the following multi-dimensional array holding all of a players quest data:
quests[0] = 78;// Store the questID quests[0][0] = 3945;// Store the 1st creature ID quests[0][1] = 2230;// Store the 2nd creature ID quests[0][2] = 3045;// Store the 3rd creature ID quests[0][0][0] = 2;// Store how many needed of the 1st creature quests[0][1][0] = 5;// Store how many needed of the 2nd creature quests[0][2][0] = 13;// Store how many needed of the 3rd creature
As we know, the above code can't be done. How do I assign certain values to each specific dimension?
1.Create one 2-dimensional array. The array will consist of numbers from 1 to 10. And will also contain the number in words. Display the values of the 2-dimensional array.
Sample output: 1 - One 2 - Two 3 - Three
Paste the program code here:
2.Create a program that will accept two integer numbers. These integer numbers will be the limit of the multiplication table. Store the values in a two dimensional array.
Sample output: Enter x: 3 Enter y: 2 123 246
Paste the program code here:
3. Determine the output produced by the following program segment.
int ROWS = 3; int COLS = 4; int [ ] [ ] val = {{8,16,9, 52},{3,15,27,6},{14,25,2,10}}; for (int i=0; i < ROWS; i++) { for (int j= 0; j<COLS; j++) System.out.print (val [i][j] + " " ); System.out.println (); }
im working on a homework assignment t that should print all pairs of integers that sum to val. I have so far finished except It prints duplicate values (ie (3,1) and(1,3) for values that add to 4) . how can i remove these duplicate pairs of values?
#include <iostream> #include <map> #include <vector> using namespace std; void printPairs( vector<int> numbers, int val){ int i;
I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"
The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?
Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:
int main() { FILE *p; p = fopen("input.csv", "r+"); if(p == NULL) { puts("The file could not be opened");
[Code] ......
But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:
int main() { FILE *p; int lines = 1; char ch; p = fopen("input.csv", "r+"); if(p == NULL) {
[Code] .....
But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.
How can I concatenate two 2-dimensional int arrays into one larger 3-dimensional array. This question is also valid for the 3-dimensional vectors. I know the command for the one dimensional vector as:
While removing duplicate elements from an array, if more than 4 array elements are same then removal does not work. however my logic seems to be alright. i reckon there is a problem with the conditions and assignments in the three for loops that i have used. the program is as follows:
Code: /*c program to remove duplicate elements in an array*/ #include<stdio.h> int main(void) { int array[30],i,j,k,n; printf("
[Code] ....
Take for instance if the input elements are 1,1,1,1,1,2,2,3,5 then after removal of duplicacy the array is 1,1,2,3,5.
I had a hard question in my C++ final exam and I'm trying to solve it for the last 3 days. I haven't succeded yet! Here is the question: You have a one-dimensional array A[20]={1,2,3,4,...,20} and B[5][4] you have to assign the A array's elements to the B array but there is an order which is: B[5][4] = { { 12, 9, 11, 10 }, { 14, 7, 13, 8 }, { 16, 5, 15, 6 }, { 18, 3, 17, 4 }, { 20, 1, 19, 2 } } and there is a restriction: you can only use ONE for statement, nothing else!
#include <iostream> #include <iomanip> using namespace std; int main(){ int A[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; // define A array's elements. int B[5][4] = { 0 }, k = 1; // define B array and k counter.
[code]....
I can't narrow the statements to one,This program works perfectly but it shouldn't be that long, we need ONLY ONE FOR statement, not two!
The goal is to merge two files of names, sort them and remove duplicates.I've managed to merge the two files into a single char array and sort them with a function so they are alphabetical.I'm having problems removing the duplicate entries from the array. Here is my code:
I have a 3D array that contains 200 strings. I'm trying to copy all these strings into a 2D array. How can this be done? This is what I have so far but it isn't working correctly.
Code: for(int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { dest[i][j] = source[0][i][j]; } }
The finished product would be with 100 rows, 2 columns.
Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.
In order to fix this error: [URL]...
I had to change my array initialization to one with a star in front of it:
char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"}; to: char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
I also changed my 2nd array to one with a star in front of it: char *a2[20];
What does this mean exactly? Putting a star in front of an array?
Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:
Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is
I want to make a program that asks the user for a message and then print out a large graphic of that message. For example, if the user types "he" I want to print out
H..................H EEEEEEEEE H..................H E H..................H E H..................H E HHHHHHHHHH EEEEEEEEE H..................H E H..................H E H..................H E H..................H EEEEEEEEE
(treat the periods as spaces. I only put them there because it wouldn't separate the H's correctly.)
I will loop this to continue until the user types quit.
1. How would I set this up to store the user input characters into an array?
2. How would I print out the stored data in the shape of the word?