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.
This post just input 1 Array is fine, no need for integer n? @@
Ah. Usually, I tell the number of array elements to know how many times to enter. You use python so, other friends use c,c++ desperately needs this.
Scared the high man showed me the number counting lesson and I didn't know how to enter the data!!!!
The beginning of the post is a bit redundant.
Once you have received the integer n, what else do you need to do to enter the second line.
So it is better to enter n integers and manually enter n integers to form an array.
If you enter it yourself, where can you get it to test?
#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);
Xuat Mang(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;
}
Why did I submit it with the correct result but it said Wrong. Just help me with my mistake
Please compare Test output vs your output.
the test output vs your output is exactly the same bro :((
I don't have a line down, my friend
#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
:)) where am i wrong
Test Input:
6
-3 6 -4 7 2 1
Test Output:
7 -4
Your Output:
-3 6 -4 7 2 1
7 -4
My output has input too. :v
Still can't pass even though the result is correct
Please compare your output and test output.
If it doesn't say anything, the submission may be over, so you can't submit it. Try again at the beginning of the day.