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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:37:35+00:00 2026-05-31T23:37:35+00:00

I have an array and I have integers in the array. I’m trying to

  • 0

I have an array and I have integers in the array. I’m trying to count the number of times the integers in the array repeat themselves. After that I want to print the percentage. This is what I have so far.

for(i = 2; i < 8; i++){
    mmblk[i] = (num[i] / bsize);   //mmblk[i] =0,0,1,9,0,1
    if(mmblk[i] == mmblk[i]){      
        count ++;
        p = count/num[0];
        percent = (p * 100);
    }
}
printf("Highest possible hit rate = %d/%d = %d %\n", count, num[0], percent);//num[0]=6

For the output I get:
Highest possible hit rate = 0/6 = 0

The output should look like:
Highest possible hit rate = 3/6 = 50 %

I know there is something way wrong going on but I can’t figure out what it is. Any help will be greatly appreciated.

  • 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-31T23:37:37+00:00Added an answer on May 31, 2026 at 11:37 pm

    So if I understand correctly, you are looking for the maximum number of repeated values in the array.

    func( {1,2,3} ) = 0
    func( {1,1,3} ) = 2
    func( {1,1,1} ) = 3
    

    To get the percentage, you simply divide this result by the length of the array.

    The problem is your function is way too simple, and not really at all the solution.

    The solution I’m coming up with on first approach, is to have another array called counts. This is the same length as your source array. It ends up being the number of times each number in the source array appears.

    For each item in the source array, you count how many times that number appears, and store that result in counts. Then you find the maximum of the counts array, and you have a) the max repeats value you’re looking for, and b) the index of the corresponding maximum-repeated-value from the source array.

    For the example {0,0,1,9,0,1} :

    src    counts
      0       3        Max 
      0       3
      1       2
      9       1
      0       3
      1       2
    

    One optimization to this, is while you are counting, if you encounter the same number earlier in the array, you can stop, because you already have counted repeats for that value.

    With that in place, your result is:

    src    counts
      0       3        Max 
      0       0        
      1       2
      9       1
      0       0
      1       0
    

    Another optimization is to only start counting from your current index in the array. This works for the same reason as the other optimization.

    Results:

    src    counts
      0       3        Max 
      0       2
      1       2
      9       1
      0       1
      1       1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of integers: int[] number = new int[] { 2,3,6,7 };
Assume that we have multiple arrays of integers. You can consider each array as
Basically I have and array of integers that vary in size. I need to
I have a 2D array of integers that represent groupings (crystal grains) on a
Suppose I have a sorted array of integers int[] , and I want to
I have a class that internally is just an array of integers. Once constructed
If we have an array of integers then how can we find the number
In C#, I have an array of integers, that represent the primary keys of
I have a hash that maps an array of integers to an integer. For
Assume that we have an array of integers (3x3) depicted as follows: +-+-+-+ |

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.