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 7973675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:10:25+00:00 2026-06-04T08:10:25+00:00

I am trying to implement a solution to the following problem with vectors (arrays)

  • 0

I am trying to implement a solution to the following problem with vectors (arrays) in C.
I want to input a number and the number of times it occurs.

Here is an Example:

Imput n:  5

Imput num 1: 8
Imput num 2: 9
Imput num 3: 8
Imput num 4: 5
Imput num 5: 5

The program will now show this:

Number 8: 2 occurences
Number 9: 1 occurences
Number 5: 2 occurences

but mine show:

Number 8: 2 occurences
Number 9: 1 occurences
Number 8: 2 occurences
Number 5: 2 occurences
Number 5: 2 occurences

how can i do??? TY

#include <stdio.h>
#include <stdlib.h>
#define SIZE 20

int main ()
{
    int vett1[SIZE], vett2[SIZE];
    int n, i, j;
    int flag;

    printf ("Imput n: ");
    scanf  ("%d", &n);

    for (i=0; i<n; i++)
    {
        printf ("Imput %d di %d: ", i+1, n);
        scanf  ("%d", &vett1[i]);
    }

    printf ("\n\nYour vector: : ");

    for (i=0; i<n; i++)
    {
        printf ("%d ", vett1[i]);
    }

    for (i=0; i<n; i++)
    {
        flag=0;

        for (j=0; j<n; j++)
        {
            if (vett1[j] == vett1[i])
            {
                flag++;
            }
        }

        vett2[i] = flag;
    }

    printf ("\n\n");

    for (i=0; i<n; i++)
    {
        printf ("Number %d: %d occurencese\n", vett1[i], vett2[i]);
    }

    return 0;
}
  • 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-06-04T08:10:26+00:00Added an answer on June 4, 2026 at 8:10 am

    You need a way to keep track of (1) numbers, and (2) the number of occurences. Think like this: If you were doing it by hand, with pencil and paper, and not with a computer, how would you do it?

    You would probably need a piece of paper with a small table on it, with numbers in the left column and the number of occurences in the right column. You’d then go through the numbers (in your case 8, 9, 8, 5, 5) and for each number, you would check if it’s in your table. If it already is in the table, increment the count by one. If it isn’t in the table, put it on a new line, with the count 1.

    Now all you need to do is to implement this table not as a table on paper, but as some sort of data structure.

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

Sidebar

Related Questions

I'm trying to implement a solution using .htaccess and wildcard subdomains so that http://subdomain.example.com
I'm trying to implement the following feature: I want just one css file to
I have a following problem. I'm trying to implement a model for my QTreeView
I'm trying to implement this accepted solution for displaying a custom error message: https://stackoverflow.com/a/5229581/141172
Just trying to implement a simple audit logging solution with Grails 2.0.2 and it
I'm trying to implement chained filter dropdown using just javascript - jquery. The solution
The background is : I am trying to implement an automated integration test solution.
I'm trying to decide how to implement a very basic licensing solution for some
I've been trying excessively hard to implement a good open id solution into asp.net
While trying to implement an MVC file upload example on Scott Hanselman's blog. I

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.