December 23, 2018
Min max in the array
Threads: Enter array of n integers. Find the largest and smallest number in 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 line of 2 number is the largest and the smallest number in the array separated by spaces.
For example:
input: 3 1 2 3 output: 3 1
You are not logged in? Log in to Submit Now!
13 Comments
Add a Comment
You must be logged in to post a comment.
Bài này đầu vào chỉ cần 1 mảng là được đâu cần số nguyên n đâu nhỉ? @@
Ah. Thường thì mình cho biết số lượng phần tử mảng để còn biết càn nhập bao nhiêu lần ý. Bạn dùng python nên vậy, các bạn khác dùng c,c++ rất cần cái này.
hù hù cao nhân chỉ tui cái bài đếm số với tui không biết nhập liệu như nào cả!!!!
Đầu bài ra hơi thừa một tí.
Đã nhận số nguyên n rồi thì nhập dòng thứ hai làm gì nữa đâu.
Nên để là nhập số nguyên n và tự nhập vào n số nguyên để tạo thành mảng thì tốt hơn.
Tự nhập thì lấy đâu ra test hả bạn 🙂
#include
void NhapMang(int a[], int n)
{
int i;
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
void XuatMang(int a[], int n)
{
int i;
for (i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
int main()
{
int i, n;
int Max, Min;
scanf("%d",&n);
int a[n];
NhapMang(a,n);
XuatMang(a,n);
Max=a[0];
Min=a[0];
for(i=1;iMax)
{
Max=a[i];
}
if(a[i]<Min)
{
Min=a[i];
}
}
printf("\n%d %d", Max, Min);
return 0;
}
Sao submit nó ra kết quả đúng mà lại thông báo Wrong vậy ạ. Chỉ giúp em lỗi sai ạ
Bạn so sánh Test output vs your output nhé.
phần test output vs your output đều giống hệt nhau anh ạ :((
ko có in xuống dòng đâu bạn ơi
#include
using namespace std;
int main()
{
int a[100], n;
China >> n;
for (int i = 0; i > a[i];
}
for (int i = 0; i < n; i++)
{
cost<< a[i]<<" ";
}
int max = -999, min = 999;
for (int i = 0; i < n; i++)
{
if (max a[i])
{
min = a[i];
}
}
cost << "\n";
cost << max << " " << min;
return 0;
}
———————————————-
1. Wrong Answer
Test Input:
4
2 4 5 1
Test Output:
5 1
Your Output:
2 4 5 1
5 1
2. Wrong Answer
Test Input:
1
1
Test Output:
1 1
Your Output:
1
1 1
3. Wrong Answer
Test Input:
6
-3 6 -4 7 2 1
Test Output:
7 -4
Your Output:
-3 6 -4 7 2 1
7 -4
4. Wrong Answer
Test Input:
5
-3 -2 -4 -6 -1
Test Output:
-1 -6
Your Output:
-3 -2 -4 -6 -1
-1 -6
:)) em sai chỗ nào vậy ạ
Test Input:
6
-3 6 -4 7 2 1
Test Output:
7 -4
Your Output:
-3 6 -4 7 2 1
7 -4
Output của em có cả input kìa. :v
Vẫn ko pass dù kết quả ra đúng
Please compare your output and test output.
Nếu nó ko thông báo gì có thể đã hết lượt submit nên bạn ko submit được nhé. Try again at the beginning of the day.