Home > Back-end >  The index to calculate the maximum and its location
The index to calculate the maximum and its location

Time:09-24

 # include & lt; stdio.h> 
# define N 10
Void ReadScore (int score [], int n)
{
int i;
Printf (" Input score: ");
for (i=0; I{
The scanf (" % d ", & amp; Score [I]);
}
}

Int FindMax (int score [], int n)
{
Int Max, I, maxIndex;
Max=score [0];
MaxIndex=0;
for (i=1; I{
If (score [I] & gt; Max & amp; & I> MaxIndex)
{
Max=score [I];
MaxIndex=I;
}
}
return max;
}

Int FindMaxIndex (int score [], int n)
{
Int Max, I, maxIndex;
Max=score [0];
MaxIndex=0;
for (i=1; I{
If (score [I] & gt; Max & amp; & I> MaxIndex)
{
Max=score [I];
MaxIndex=I;
}
}
Return maxIndex;
}


Int main ()
{
Int score [N], Max, maxIndex, N.
Printf (" Input n: ");
The scanf (" % d ", & amp; n);
ReadScore (score, n);
Max=FindMax (score, n);
MaxIndex=FindMaxIndex (score, n);
Printf (" score [] % d: % d \ n ", maxIndex, Max).
return 0;
}

CodePudding user response:

What is the problem? Output the result of wrong or zha drops, the other maxIndex don't have to write a function alone, content of the two functions, the return value is different, the right to hand in, and the main function maxIndex address reference to pass and address

CodePudding user response:

reference 1st floor CHXCHXKKK response:
what is the problem? Output the result of wrong or zha drops, the other maxIndex don't have to write a function alone, content of the two functions, the return value is different, the right to hand in, and the main function maxIndex address reference to pass and address
output if I write a main function how do I modify output? In what way should I ah I wrote that the results be reused

CodePudding user response:

If I write in the output is

 int FindMax (int score [], int n) 
{
Int Max, I, maxIndex;
Max=score [0];
MaxIndex=0;
for (i=1; I{
If (score [I] & gt; Max & amp; & I> MaxIndex)
{
Max=score [I];
MaxIndex=I;
}
}
The return of Max, maxIndex;
}

Int main ()
{
Int score [N], Max, maxIndex, N.
Printf (" Input n: ");
The scanf (" % d ", & amp; n);
ReadScore (score, n);
Max=FindMax (score, n);
MaxIndex=FindMax (score, n);
Printf (" score [] % d: % d \ n ", maxIndex, Max).
return 0;
}

CodePudding user response:

Is your maximum score [maxIndex], you have been found out,

CodePudding user response:

quoted wu, 4/f * * reply:
score [maxIndex] is the maximum you, have you found out,

Positive solution,

CodePudding user response:

quoted wu, 4/f * * reply:
score [maxIndex] is the maximum you, you have been found out,
I suddenly found that I forgot to put this figure the results not so can't help me take a look

CodePudding user response:

refer to 6th floor of the double cup with wine reply:
Quote: refer to 4th floor * * reply wu:

A maximum score [maxIndex] is your, you have been found out,

Positive solution,
I suddenly found that I forgot to put this figure the results not so can't help me take a look

CodePudding user response:

MaxIndex is 0 indicates the first, so the output score [1],
If you want to output 2, put the
Printf (" score [] % d: % d \ n ", maxIndex, Max).
Change
Printf (" score [] % d: % d \ n ", maxIndex + 1, Max).

CodePudding user response:

This is what I want the results

CodePudding user response:

refer to the eighth floor of the time not to reply:
Quote: refer to the sixth floor of the double cup with wine reply:
Quote: refer to 4th floor * * reply wu:

A maximum score [maxIndex] is your, you have been found out,

Positive solution,
I suddenly found that I forgot to put this figure the results not so can't help me see
can you less a word

CodePudding user response:

refer to 7th floor of the time not to reply:
Quote: refer to 4th floor * * reply wu:
score [maxIndex] is the maximum you, you have been found out,
I suddenly found that I forgot to put this figure the results not so can't help me see
can beat one less word

CodePudding user response:

The return of Max, maxIndex;
This usage is wrong, a c + + can only return a value,
The above the actual mountain equivalent
Return maxIndex;
So directly use
Max=score [maxIndex]; Take the maximum value,

CodePudding user response:

Array subscript starting from 0, maximum: score [maxIndex] biggest sort: maxIndex + 1

CodePudding user response:

wine offering references to the 13th floor double cup reply:
return Max, maxIndex;
This usage is wrong, a c + + can only return a value,
The above the actual mountain equivalent
Return maxIndex;
So directly use
Max=score [maxIndex]; Take the maximum,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related