C :: Removing Duplicate Elements From Array

Nov 4, 2013

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.

View 3 Replies


ADVERTISEMENT

C++ ::  Algorithm To Read Duplicate Array Elements - Return First Duplicate Value Only

Oct 23, 2014

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;

[Code] .....

View 6 Replies View Related

C/C++ :: Removing Duplicate Values From Map?

Mar 1, 2015

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;

[code]....

View 2 Replies View Related

C++ :: Removing Duplicate Strings In A Vector?

Sep 1, 2014

I'm trying to create a database/search engine program and I'm having remove duplicate strings from a vector. I'm mostly just trying to make it so that if 2 or more movie have the same title in the database, it will remove the duplicates and just print out one copy of the movie console. I tried using the unique() command, but it doesn't seem to work.

code:

#include <iostream>
#include <string>
#include <vector>

[Code].....

View 2 Replies View Related

C++ :: Storing 10 Elements In Array And Delete Duplicate Terms

Jul 19, 2014

How to store 10 elements in an array and delete the duplicate terms ? ( its a single dimension array )

View 5 Replies View Related

C/C++ :: Erasing / Removing Elements From A Vector?

Mar 23, 2015

I am working on a project for class where I use a parent Shape class with circle, rectangle, ect. Classes inheriting from that. Along side these I use a class called Scene. In main I need to create a scene and add some shapes to a vector in scene.

vector<Shape*> shapes

I need to use functions addShape(Shape* shape) and a delete shape method. I have the addShape finished. The problem I am having is with the delete method. Is there a way that I can use something like deleteShape(Shape* shape)? Is it possible for me to delete a specific shape from the vector by passing in that shape, or can it only be done using index? I have looked at the documentation for std::vector as well as std::vector::erase. I am wondering this because if I use index values and do something like

void Scene::deleteShape(unsigned int x) { shapes.erase(shapes.begin() + x ); }

It will lead to some errors later on due the the changing size and indexes of the vector and elements.

View 4 Replies View Related

C++ :: How To Duplicate String Array

Sep 8, 2014

I'm trying to duplicate a string array. I created a function called duplicate but, when i run it, it gives me an error... what is wrong with it?

#include <iostream>
#include <string>
#include <fstream>
#include <array>
#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))

[Code] .....

View 3 Replies View Related

C :: Remove Duplicate Strings From Char Array

Apr 15, 2014

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:

Code:

#include <stdio.h>
#include <string.h>
#define NUMSTR 10
#define STRLNG 9

[Code]....

View 3 Replies View Related

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.

View 1 Replies View Related

C :: Removing Vowels Defined As Characters From Array

Dec 5, 2013

My question is how create a function to remove all vowels defined as characters('a' 'e', 'i', 'o', and 'u') from the array provided to it.

An example of how the function should work:

input: Hello world, how are you?
output: Hll wrld, hw r y?

Code:
int removeVowels(char arr[]) {
int i;
//move through each element of the array
for(i = j; arr[i] != '/0'; i++) {
//if the last character was a vowel replace with the current
//character

[Code] .....

View 9 Replies View Related

C :: Find Duplicate Numbers And Numbers Found Once In Array

Dec 7, 2013

Question: How to find a duplicate numbers and numbers found once in array.

View 7 Replies View Related

C++ :: Accept Integer Array And Its Size As Arguments And Assign Elements Into 2 Dimensional Array

Jan 10, 2015

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

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

View 1 Replies View Related

C++ :: Write Function That Takes Array And Returns True If All Elements In Array Are Positive

Jan 21, 2013

Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.

View 6 Replies View Related

C++ :: Assigning Elements Of 1-D Integer Array Into 2-D Array Of Integers

Sep 27, 2013

I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :

1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
"

View 7 Replies View Related

C/C++ :: Difference In Array Name And Address Of First Elements Of Array

Aug 13, 2014

I have just started learning C language, I have read that array name is the pointer to the first element of array.

So,technically both a and a[0] should have different memory address and a should hold address of a[0],

But when I declare an array and print the address:

int a[5]={2,4,6,8,10};
printf("The address of a and a[0] are &d and %d",&a,&a[0]);
Output is: The address of a and a[0] are 2358832 and 2358832

Why I am getting the same result, shouldn't I be getting different memory address for both a and a[0].

View 2 Replies View Related

C++ :: How To Add Elements To Array

Apr 5, 2013

I've a file that looks like this:

84484-37.96-Castor, Kathy
39050-69.68-Chandler, Ben
26183-70.84-Costello, Jerry

I have successfully read each element the id, grade and name into 3 separate array. Now i need to add a new student with an id and grade

How do i do this?

This is what I have.

int addStudent( int Iarray[], double dArray[], string sArray[], int newID,
double newGrade, string newName, int size ) {
char ready;
int index;
cout << endl;
cout << "Enter new student ID number : ";

[Code]...

View 4 Replies View Related

C/C++ :: Elements Outside Array?

Oct 27, 2014

I have a question regarding the elements of an array. Suppose I have a 3 by 3 string array (char x[3][4] ) , and I initialize all the elements to x's , the array would then look like this :

xxx
xxx
xxx

I'm curious if there will be a value if I try to access and element outside the array. As I have to write a code to determine if I have reached the end of an array. The only way I can think of is to border the entire array with o's , making it look like this :

ooooo
oxxxo
oxxxo
oxxxo
ooooo

Is there any other way to do this?

View 5 Replies View Related

C :: Trying To Concatenate 2 Elements From Array

Oct 19, 2013

Trying to concatenate the 1st and 2nd element from an array of chars. Then this to be used as a hex value.

so for example
specs[0]='f'
specs[1]='4'

concatenate_value=0xf4

View 9 Replies View Related

C :: Reversing Elements In Array

Apr 15, 2014

Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the number of elements in thearray . The function reverses the elements of the array . The function does not return a value .

Code:
void reverse(int a[], int num) {
for ( int i=0; i <= num/2 ; i++){
int temp = a[i];
a[i] = a[num-i-1];
a[num-i-1] = temp;
} }

This is supposed to be the answer but I'm not quite sure why this is. I understand everything up until the actual loop. For one, shouldn't "int i" be declared outside the loop (I thought perhaps this was an error in the solutions)?

The main thing that I do not understand is the conditional statement.

Code: i<=num/2;

I don't understand why the "num/2" is necessary here. Also I can't really remember but is there a command that actually reverses an array?

View 5 Replies View Related

C++ :: Setting All Elements Of Array To 0

Sep 18, 2013

I'm trying to set all the elements of my array to 0 but nothing seems to be working.

.h
#ifndef ServerGroup_h
#define ServerGroup_h
class ServerGroup {
public:
ServerGroup(const int&);

[Code] .....

I want to set each element of the array in servers to 0 based on what is passed into size by numArray.

View 9 Replies View Related

C++ :: Reverse Elements Of Array

Apr 11, 2014

I am trying to write a program that reverses the elements of an array by using an function 'myreverse'. The function should reverse original array and return nothing.

In my program, the function 'myreverse' is not getting invoked and the original array is being displayed as it is.

#include <iostream>
using namespace std;
void myreverse(int arr[],int n) {
int *p=&arr[n-1];
int temp;
for(int i=0;i<n;++i)

[Code] .....

View 5 Replies View Related

C++ :: Adding Array Elements Together?

Sep 28, 2013

I'm having trouble getting my array to add its values together. I have a similar program running fine with the exact same equation. I am not so naive as to believe that this means it should run with every program but I'm at a loss as to what to do.

#include <iostream>
#include <iomanip>
using namespace std;

[Code].....

View 2 Replies View Related

C++ :: Moving Elements In An Array?

Dec 20, 2013

im trying to get my array to display 5,1,2,3,4 from the original 1,2,3,4,5.

void values::movevalues()
{
cout << "postcondition
";

[Code]....

something in this part is making it go wrong, it displayes the original array fine but when it tries to shift it it goes haywire. EDIT: also how would i add elements onto the array?

View 10 Replies View Related

C++ :: Elements Greater Than The Array Max?

Dec 11, 2013

im trying to write a program that finds the max in an array and divedes it by two than oututs a modfied list with all the elements greater than the max/2.

I got the first part but just not sure how to find the elements greater than the max/2 and output them correctly into the modfied list.

#include <iostream>
#include <iomanip>
using namespace std;

[Code].....

View 2 Replies View Related

C++ :: Swapping Elements In Array?

Nov 25, 2014

I thought I'm done doing mg activity, but my professor said that we need to use a Temporary Variable for Swapping but where to put it.

Here is his activity:

Activity: Swapping Create a program that accepts a 10-element array of type int. Where the 1st user-input is stored in the 1st element of the array; the 2nd user-input is stored in the 2nd element of the array; so on so forth until the last user-input stored in the last element of the array. Your source code should be able to SWAP the values of the 1st and 10th; 2nd and 9th; 3rd and 8th; 4th and 7th; and 5th and 6th elements. It should display the values of the original and the swapped values of the array. example:

Enter 10 integer values:
array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4

[Code]....

View 1 Replies View Related

C++ :: Increase Value Of Elements Of Array

Jan 18, 2013

I want to increase the value of some elements of an array according to a certain condition. For example the following code:

array <int, 100> myArray = {};
myArray.fill(0);
for(int i=1; i<5; i++)
*(myArray.being()+1) ++;

I was hoping myArray[1] = 5. But it actually did not work. But if I code:

int myVar = 0;
for(int i=1; i<5; i++)
myVar ++;

Result: myVar = 5.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved