Array int A[20]; . How to assign int k; to a variable int k; any cell number? k = A[9]; - so we assign the element itself from cell 8. And its number?
- one@ art13, to begin with, answer yourself the question: " what is a cell number? ". After that, the question you asked will probably disappear. - avp
- The cell number is my required))))) - art13
|
1 answer
Assign cell number A[9]
k=9 - The fact is that I am looking for the smallest value in the array and it is unknown in advance. When finding this value, you need to remember its number in the array. And your expression is wrong. When referring to the value in the array, the count goes from 0 and not from 1. - art13
- I wonder how you then look for the minimum, without referring to the elements of the array? It seems like to find it, you need to compare 2 numbers and one of them will be
A[index], which means that the index of the minimum will beindex. - den94 - oneYou first define the terms. And the search for the index of the minimum value for the array
int amin = A[0], kmin = 0; for(int k=1; k<20;k++) if (A[k] < amin) {kmin = k; amin = A[k];}int amin = A[0], kmin = 0; for(int k=1; k<20;k++) if (A[k] < amin) {kmin = k; amin = A[k];}int amin = A[0], kmin = 0; for(int k=1; k<20;k++) if (A[k] < amin) {kmin = k; amin = A[k];}- alexlz - I have a search code and everything works. The last speaker helped. Not that you just need to take i and assign k. I step through i. - art13
|