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

  • Home
  • SEARCH
  • 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 7614907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:31:19+00:00 2026-05-31T02:31:19+00:00

I have created a function to count the duplicate items in array . And

  • 0

I have created a function to count the duplicate items in array .
And everything is fine . but I want to output the unique items only , and this is my problem .

My function:

void RepeatedCounter(int n){
    int i, j, temp, count= 0;
    int *Numbers = new int[n];
    for(i=0;i<n;i++){
        cout << "Enter the number (" << i+1 << "): "; 
        cin >> *(Numbers+i);
    }
    cout << "---------------------\n";
    for(i=0;i<n;i++){
        temp = *(Numbers+i);
        for(j=0;j<n;j++){
            if(temp == *(Numbers+j)){
                ++count;
            }
        }
        if(*(Numbers+i+1) != temp)
        cout << *(Numbers+i) << "= " << count << endl;
        count= 0;
    }

    delete []Numbers;
}

Main function:

int Num_Of_Digits= 0;
cout << "How many numbers: ";
cin >> Num_Of_Digits;
RepeatedCounter(Num_Of_Digits);

Example:

Inputs  
1  
5  
3  
5  
1  

Wrong result (current output)

1= 2   
5= 2  
3= 1  
5= 2   
1= 2  

What I want

1= 2     
5= 2  
3= 1  
  • 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-31T02:31:20+00:00Added an answer on May 31, 2026 at 2:31 am

    Try this,

    for(i=0;i<n;i++){
        count= 0;
        temp = *(Numbers+i);
        bool found = false;
        for(j=0;j<n;j++){
            if(temp == *(Numbers+j)){
                ++count;
            }
        }
        for(j=i+1;j<n;j++) {
            if(temp == *(Numbers+j)){
                found = true;
            }
        }
        if(found) continue;
        if(*(Numbers+i+1) != temp)
        cout << *(Numbers+i) << "= " << count << endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a function for a thread, but I want to pass multiple
I have created this function to check abecedarian with while loop (A word is
Hey, so I have created a function to check the DB for unique entries,
I have created a JS function which executes fine when it's included an the
I have created a custom function and I am getting this error. I dont
I have created a add input field function which is working fine. I would
i have created a module with this among others this function in it: <?php
I have created a signup page on my site, but the javascript validation function
I have created a function that creates a dynamic string array with dynamic string
I have a simple recursive array function that looks like this: function recursive_array($results) {

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.