I have defined an array of structs and initialized the data, how do I find the maximum value?

Updated on technology 2024-04-07
5 answers
  1. Anonymous users2024-02-07

    Your mistake is that each loop pair is compared to m, which is just the value of the first element in the array. That is, as long as the element in the array is larger than the first element, this value will be assigned to e. So you get the last value in the array that is greater than m.

    For example, if the number in the array is 72, 70, 80, 75, 88, 62, 77, then your program will get 77

    Your program can be changed like this:

    int i;

    int m=stu[0].sx;

    int e;

    for(i=1;i<=10;i++)

    if(stu[i].sx>m)

    m=stu[i].sx;Replace e with m

    elseprintf("The highest score in math is: %d",e);

  2. Anonymous users2024-02-06

    There is no need to use the e variable.

    int i;

    int m=stu[0].sx;

    for(i=1;i<=10;i++)

    if(stu[i].sx>m)

    m=stu[i].sx;

    printf("The highest score in math is: %d",m);

    As long as the data is initialized correctly, the correct results are likely to be obtained.

  3. Anonymous users2024-02-05

    That's fine, int i;

    int m=stu[0].sx;

    int e;

    for(i=1;i<=10;i++)

    if(stu[i].sx>m)

    m=stu[i].sx;Modifications. elsem=m;Modify the place, of course you can cancel the **.

    e=m;Modifications.

    printf("The highest score in math is: %d",e);

  4. Anonymous users2024-02-04

    stu[0].What is stored by SX.

    That e doesn't seem to be useful, just use m to store the maximum value.

  5. Anonymous users2024-02-03

    A Huffman tree is given n weights as n leaf nodes to construct a binary tree, and if the length of the weighted path of the tree reaches the minimum, such a binary tree is called the optimal binary tree, also known as the Huffman tree. The Huffman tree is the tree with the shortest weighted path length, and the nodes with larger weights are closer to the roots.

    Example: 1. 、... w1 and w2, wn is seen as a forest with n trees (each tree has only one node);

    2. The tree with the smallest weight of two root nodes is selected and merged in the forest as the left and right subtrees of a new tree, and the root node weights of the new tree are the sum of the weights of the root nodes of the left and right subtrees;

    3. Delete the two selected trees from the forest and add new trees to the forest;

    4. Repeat steps (2) and (3) until there is only one tree left in the forest, which is the Huffman tree that you have sought.

Related questions
10 answers2024-04-07

Here's a C implementation that assigns an array a[10] to p[n]: >>>More

12 answers2024-04-07

Impress her with sincerity. First of all, you have to be patient yourself, because it takes a long time for a person's wound to heal completely.

12 answers2024-04-07

In the past, a girl had a good relationship with me, and she also said something similar to me, saying that the girl was not suitable for me. >>>More

6 answers2024-04-07

However, the company with a registered capital of more than 500,000 yuan is: (1) a company mainly engaged in production and operation; (2) Companies mainly engaged in commodity wholesale; (3) commercial retail companies; (4) Science and technology development, consulting, and service companies. Registered capital, also known as authorized capital, is the amount of capital contribution subscribed or the total amount of share capital subscribed by all shareholders or promoters as stipulated in the articles of association of a company-based enterprise, and is registered with the company registration authority in accordance with the law.

4 answers2024-04-07

If the company is divided into dormitories, the company's conditions do not allow, it is best not to embarrass the leader, the number of people is not your own thing, in case you open this head the leader will be very passive to do the work. You can negotiate privately with the people in your dormitory, and everyone will take turns to live for half a year, and the person who lives in the company dormitory will subsidize how much money each month will give to another person to rent a house outside. In this way, everyone has their own independent space, and there will not be too much loss of economy. >>>More