Jump to content

Because the loop will repeat so long as j is less than 5. Once it is equal to 5 then it is no longer less than 5, therefore j will be equal to 5 once the for loop exits.

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to comment
https://linustechtips.com/topic/70820-whats-going-on-here/#findComment-970651
Share on other sites

Link to post
Share on other sites

The loop will continue last time making j=4 into 5 and stop then. There is your mistake. Have to stop it in the last go before it adds the last 1.

][ CPU: Phenom II x6 1045t @3,7GHz ][ GPU: GTX 660 2GB ][ Motherboard: Gigabyte GA-MA770T-UD3P ][ RAM: 8GB @1450Mhz CL9 DDR3 ][ PSU: Chieftec 500AB A ][ Case: SilentiumPC Regnum L50 ][ CPU Cooler: CoolerMaster Hyper 212 Evo & Arctic MX4 ][

Link to comment
https://linustechtips.com/topic/70820-whats-going-on-here/#findComment-970660
Share on other sites

Link to post
Share on other sites

The loop will continue last time making j=4 into 5 and stop then. There is your mistake. Have to stop it in the last go before it adds the last 1.

But then if the last element was the highest you would miss it.

 

A simple solution would be to store the index along with the max and then print that.

Link to comment
https://linustechtips.com/topic/70820-whats-going-on-here/#findComment-970871
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×