Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:18:25+00:00 2026-05-25T16:18:25+00:00

I have 2 arrays called xVal , and yVal . I’m using these arrays

  • 0

I have 2 arrays called xVal, and yVal.

I’m using these arrays as coords. What I want to do is to make sure that the array doesn’t contain 2 identical sets of coords.

Lets say my arrays looks like this:

int xVal[4] = {1,1,3,4};
int yVal[4] = {1,1,5,4};

Here I want to find the match between xVal[0] yVal[0] and xVal[1] yVal[1] as 2 identical sets of coords called 1,1.

I have tried some different things with a forLoop, but I cant make it work as intended.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:18:26+00:00Added an answer on May 25, 2026 at 4:18 pm

    You can do it with two for loops:

    int MAX=4; //number of elements in array
    for (int i=0; i<MAX; i++)
    {
        for (int j=i+1; j<MAX; j++)
        {
            if (xVal[i]==xVal[j] && yVal[i]==yVal[j])
            {
                //DUPLICATE ELEMENT at xVal[j], yVal[j]. Here you implement what
                //you want (maybe just set them to -1, or delete them and move everything
                //one position back)
            }
        }
    }
    

    Small explanation: first variable i get value 0. Than you loop j over all possible numbers. That way you compare xVal[0] and yVal[0] with all other values. j starts at i+1 because you don’t need to compare values before i (they have already been compared).

    Edit – you should consider writing small class that will represent a point, or at least structure, and using std::vector instead of arrays (it’s easier to delete an element in the middle). That should make your life easier 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am having a array called temparray and have 2 seperate arrays .i have
I have a pretty simple problem. Basically I have an array called $list that
I have a struct array called AnalysisResults , that may contain any MATLAB datatypes,
Specifically, I have an array of strings called val, and want to replace all
Using Javascript, I have two arrays called array1 and array2. I set currentArrray to
I have a function, which is called sometimes with regular, sometimes dynamic arrays. If
I have an array called $times . It is a list of small numbers
I have an array of sprites called segments and I would like to skip
I have an array of objects in MATLAB and I've called their constructors in
Say I have a 2D array of random boolean ones and zeroes called 'lattice',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.