The array a has elements of data type int. The following code is intended to calculate the index of the first?
-
The array a has elements of data type int. The following code is intended to calculate the index of the first occurrence of the value that is least among all the elements of a, and to store that index in the variable minindex. int k; int minindex = 0; for ( k = 1 ; k < a.length ; k++ ) { if ( condition ) statement } Which of the following replacements for condition and statement will cause the code to work as intended? condition statement 1. a[ k ] < minindex minindex = a[ k ]; 2. a[ k ] < a[ minindex ] minindex = a[ minindex ]; 3. a[ k ] < a[ minindex ] minindex = k; 4. a[ k ] > minindex minindex = a[ k ]; 5. a[ k ] < minindex minindex = k; why is it not 2? what is it then? explain! AP's are coming and I want to understand this. Thanks
-
Answer:
3 minindex contains index of the element which is smallest Assume array contains elements as: 10, 71, 89,2, 99, 2, 200, 16 minindex k a[minindex] a[k] 0 1 10 71 As 71 is not less than 10 minindex will not change 2 89 As 89 is not less than 10 minidnex will not change 3 3 2 2 As 2 is less than 10, minindex becomes 3 4 99 As 99 is not less than 2 minindex willl not change 5 2 As 2 is not less than 2 minindex will not change 6 200 No change in minindex 7 16 No chage in minindex Finally 3 is the index of the element which contains smallest element
Betsy at Yahoo! Answers Visit the source
Related Q & A:
- How to convert a char array into an int in C++?Best solution by Stack Overflow
- Can you partition a drive without erasing data?Best solution by Yahoo! Answers
- What's a good amp for alpine type R?Best solution by Yahoo! Answers
- What is a pimpin Myspace profile layout type?Best solution by Yahoo! Answers
- Is there a website where I can type in a sentence and see if the sentence is correct or not?Best solution by textranch.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.