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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:34:48+00:00 2026-06-13T19:34:48+00:00

I have an array of integers and I’m trying to find which one is

  • 0

I have an array of integers and I’m trying to find which one is the highest and set a new integer to the highest ones value. I’m very new to C, I literally just started learning it.

There is probably some kind of logical problem with what I’m doing but I haven’t been able to spot it yet. so…

int my_array[4];
int highest_int = 0;
int i;

for (i = 0; i < 4; i++) {
    if (my_array[i] > my_array[i++]) {
        if (my_array[i] > highest_int) {
            highest_int = my_array[i];
        }
    }
    else {
        if (my_array[i++] > highest_int) {
            highest_int = my_array[i++]
        }
    }
}

So I loop through my array 4 times (4 elements) and I look at the iteration value and the next one and if the iteration value is highest I check it’s also higher than the current value of the current ‘highest integer’ and if it is I set the current highest integer to the new highest value. If the value after the iteration value is higher I do the same thing but with that value instead.

That’s what went through my head when I wrote this but when I enter 4 values it always comes out with the 3rd value in the array. No matter what I set those values to.

Can anyone tell me why?

Thanks a lot.

  • 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-13T19:34:49+00:00Added an answer on June 13, 2026 at 7:34 pm

    You’re making this way more complicated than it really is 🙂 Furthermore, you’re writing i++ in too many places; each time i++ gets executed you’re skipping over an array entry, which is probably not what you want.

    Also, there’s no need to compare to the previous value. Just compare to the highest one you’ve seen so far.

    Here’s a fixed version, just by deleting code, nothing changed or added:

    int my_array[4];
    int highest_int = 0;
    int i;
    
    for (i = 0; i < 4; i++) {
        if (my_array[i] > highest_int) {
            highest_int = my_array[i];
        }
    }
    

    Note that this incorrectly reports 0 if all numbers in the array are negative. Start off highest_int = INT_MIN in case you need to handle those correctly, or use unsigned int.

    • 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 in my core data model. It is set
I have an array of integers which represent a RGB image and would like
I have an array of integers in string form: var arr = new string[]
I have an array of integers like these; dim x as integer()={10,9,4,7,6,8,3}. Now I
Possible Duplicate: I have an array of integers, how do I use each one
I have an array and I have integers in the array. I'm trying to
If we have an array of integers then how can we find the number
Say you need to have a list/array of integers which you need iterate frequently,
I have the following array of integers: int[] array = new int[7] { 1,
I have an array of 10 integers, and k is an integer that loops

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.