How to find the maximum and minimum values in the array in c?

Updated on educate 2024-05-25
18 answers
  1. Anonymous users2024-02-11

    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

  2. Anonymous users2024-02-10

    Record the maximum and minimum values with two variables, and just scan them once.

    The sort is to kill chickens with a knife.

  3. Anonymous users2024-02-09

    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.

  4. Anonymous users2024-02-08

    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. }

  5. Anonymous users2024-02-07

    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).

  6. Anonymous users2024-02-06

    int i = ;

    int max=;

    int min = ;

    Grammar One way to do it!

  7. Anonymous users2024-02-05

    Will use c should know the bubble sorting, right? After the order, just take the first and last one.

  8. Anonymous users2024-02-04

    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);

  9. Anonymous users2024-02-03

    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;}}

  10. Anonymous users2024-02-02

    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; }

  11. Anonymous users2024-02-01

    It seems that you can only arrange the order first, and then calculate the difference.

  12. Anonymous users2024-01-31

    It's too simple, just use sort.

    int min = ;

    int max = - 1]);

    I don't need to explain. :)

  13. Anonymous users2024-01-30

    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++)

  14. Anonymous users2024-01-29

    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

  15. Anonymous users2024-01-28

    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;

  16. Anonymous users2024-01-27

    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.

  17. Anonymous users2024-01-26

    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.

  18. Anonymous users2024-01-25

    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.

Related questions
28 answers2024-05-25

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!

13 answers2024-05-25

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.

6 answers2024-05-25

A method is a series of processes to solve a problem, which may be long or short. >>>More

12 answers2024-05-25

Delete the program in the Control Panel.