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.
Đầu bài nên quy ước chỉ số mảng là từ 0 hay từ 1 sẽ thuận tiện hơn.
Đề bài nói là thứ tự rồi nhé.
Chỉ số mảng cũng chính là thứ tự dựa trên hệ quy chiếu là mảng.
Nếu đầu bài không nói rõ thì rất nhiều người sẽ nhầm ở bài này (và một vài bài tương tự nữa)
cho em hỏi vì sao chương trình này lại chạy sai vậy ạ
#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);
}
Bạn xem và so sánh Test output và Your output xem sai đâu rồi sửa đó nhé.
output đáng lẽ phải ra hai vị trí nhưng sao lại chỉ ra một vị trí đầu thôi ạ
cho t hỏi tẹo, tại sao nếu i=1 thì max =a[i] vậy
3 trường hợp đầu thì đúng còn cái cuối your output ko ra kết quả.là sai kiểu gì vậy anh ơi.