December 23, 2018
Position in the array max
Threads: Enter array of n integers. Search order (location) the largest number in the array.
Input: The first line is an integer n. The second line 2 n is an integer array, of numbers separated by spaces.
Output: A multi-line number is the order of the largest number in the array, the sequence number in ascending and separated by spaces.
For example:
input: 3 1 3 2 output: 2
You are not logged in? Log in to Submit Now!
8 Comments
Add a Comment
You must be logged in to post a comment.
At the beginning of the article, the array index should be the word 0 good word 1 It will be more convenient.
The topic is in order.
The array index is also the order based on the array reference system.
If the title of the article is not clear, many people will be mistaken in this article (and a few more similar posts)
Please tell me why this program is not working
#include
int main()
{
int i,n,max;
int a[n];
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{scanf("%d",&a[i]);
if(i == 1) max = a[i];
if(max < a[i]) max = a[i];}
for(i=1;i<=n;i++)
if(max==a[i]) printf("%d",i);
}
You can see and compare Test output and Your output to see what's wrong and then correct it.
output is supposed to show two positions but why is it showing only one first
let me ask you something, why if i=1 then max =a[i] So
3 the first case is correct and the last one does not produce results. What kind of error is it bro?.