-
Landlord: Since your question is asking the maximum value and minimum value in the array, then why do you define two ordinary arrays...
Ordinary arrays are typically used to store data or transfer data.
If you want to perform data calculations on the data in the array (including sorting, length, etc.), it is recommended to use an object of the class to save the data.
It's very convenient to create an object of the class and then you can use its various methods to manipulate the data in the array.
Of course, the landlord thinks that only rookies do this, and you can also use ordinary values to store data, and then write your own methods for data processing
-
Record the maximum and minimum values with two variables, and just scan them once.
The sort is to kill chickens with a knife.
-
Isn't it possible to make a sorting algorithm, the simplest bubbling? If you ask for performance, make a quick row, which has nothing to do with what language it is.
-
Method 1: Use ArrayList
using ;
int arr = ;
arraylist list = new arraylist(arr);
int min = ;
int max = - 1]);
Max" + max +"Minimum:"+min);
Method 2: Use? : The statement is relatively simple.
for(int i=0;ia[i]?(b=a):(b=a[i]);It only takes one round of for loops to get the maximum value, and the same goes for finding the minimum value. }
-
First, declare two variables outside to store the first finger of the entire array, assuming that both the largest and the smallest are first.
foreach(int a variable).
-
int i = ;
int max=;
int min = ;
Grammar One way to do it!
-
Will use c should know the bubble sorting, right? After the order, just take the first and last one.
-
Wrote a paragraph for you**, you refer to it.
int a = ;
int max = a[0];
int min = a[0];
for (int i = 1; i < i++)"The maximum value is:" + max);
The minimum value is" + min);
-
class program
int result1 = ;
int result2 = ;
The maximum value of the array para1 is: The index in the array is:",maxandmin[0],result1);
The minimum value of the array para1 is: The index in the array is:", maxandmin[1], result2);
private int getmaxandindex(params int pa)}}
return index;
private int getminandindex(params int pa)}}
return index;}}
-
On the first floor...
No need to sort. The function looks something like this.
int find(int list,ref int max,ref int min)
int diff = max - min;Finding the maximum value minus the minimum value return diff; }
-
It seems that you can only arrange the order first, and then calculate the difference.
-
It's too simple, just use sort.
int min = ;
int max = - 1]);
I don't need to explain. :)
-
Let's talk about your process:
First: int a = new int[3]; a[0]=0int max = a[0]; /max=0int min = a[0];min=0for (int i = 0; i < i++)
-
There are many ways to do this.
Help you find "Introduction to Algorithms" :
minnum(n)
min=a[1];
for i=2 to lenght(a)
if(min>a[i])
min =a[i]
return min
-
In defining a variable is it.
int num=0;
When the condition is true, num=i;
Since the index is calculated from 0, then the position of the last output is: i+1;
-
Their position in the array is on top of the variable in the array, so to speak, array[6]=97, this maximum, then the maximum value in this array is 6The same goes for minimals.
-
Write the array as a[c] and c as 0 9. Find out that the maximum value is 97, go to the array and check c=6, and you will know that the position is c+1, that is, the seventh number.
-
When the maximum and minimum values are obtained, the position i is stored in the variable.
If you don't want to add variables, you can iterate through them again.
There is a lot of motivation, from your teachers, friends and classmates, their encouragement and support is the biggest motivation for you, and at the same time, you should always encourage yourself and believe that you can do it! When you are tired, you can take a break, and you can chat with friends and classmates if you have nothing to do, which can not only make you cheerful and confident, but also give you more motivation, make you happy to study, happy life, bless you!
I don't know if net has this kind of control or has the function itself, if you want to write it yourself, it is to detect whether the program form is outside the screen, that is, whether the y coordinate is less than 0 and so on; It will be displayed if the mouse cursor is moving over it.
#include
#include >>>More
A method is a series of processes to solve a problem, which may be long or short. >>>More