C array, and displays its subscript Urgency Master

Updated on technology 2024-06-06
11 answers
  1. Anonymous users2024-02-11

    Dichotomy. #include""

    int search(int a,int x)int find,low,high,mid;

    find=0;low=1;high=10;

    while(!find&&low<=high)mid=(low+high)/2;

    if(x==a[mid])find=mid;

    else if(xelse low=mid+1;

    return find;

    void main()

    int i,x,a[11];

    printf("Please enter 10 numbers in ascending order");

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

    scanf("%d",&a[i]);

    printf("Please enter the number x:");

    scanf("%d",&x);

    printf("The position of the number %d in the array a is %d",x,search(a,x));

  2. Anonymous users2024-02-10

    I'll give you a **, it's relatively simple.

    int findsecondmaxvalue(int src, int count)

    else if (src[0] >src[1])else

    for (int i=2; i= max)else}}

    return secondmax;}

  3. Anonymous users2024-02-09

    There's a dumber and easier way to do it, just sort the array.

    Then the penultimate number can be output.

  4. Anonymous users2024-02-08

    2. Define lista=('a','b','c','d','e'), use the len function to judge the length of the array, alt+f10 can be seen after the execution of the result is 5, pay attention to get the value of the list with [array name + [ordinal number]].

    3. You can get the value of the element at the specified position in the array by [array name + [ordinal number]], and the premise is that the [specified position] must be less than the length of the array.

    4. When encountering such a complex array, if you want to get the value of the specified position, you must specify the position explicitly.

    5. If you want to get the correct result for a complex array, the specified position must be [Array Index].

  5. Anonymous users2024-02-07

    For ordered sequences, the most useful is a "binary lookup", or "half-split search".

  6. Anonymous users2024-02-06

    The method of finding a specified element in a one-dimensional array:

    First, define the array and assign values to the array elements.

    Enter the position value, output the corresponding element value (i.e., find the element at the specified position) first judge whether the position is legal, if it is not legal, then the output position is wrong, please re-enter the position is legal, then turn the position value into an array of subscripts, determine the data through the subscript, and output, such as: the first element of the subscript is 0, the second is 1, etc.

    Enter a numeric value, output the corresponding subscript (i.e., find the position of the specified element) loop through the array, check whether the data in the array is equal to the value to be checked, if it is equal, then end the loop early: break;

    Otherwise, continue the cycle and check the next number.

    Once you have traversed through all the array elements, end the loop.

    After the loop ends, check whether the value of the loop variable exceeds the total number of elements in the array, if not, it means that the corresponding data has been found, and its subscript position is output, otherwise, the output does not find the corresponding element.

  7. Anonymous users2024-02-05

    include""

    void main( )

    For example, 10 elements are 0-10;

    int k=0;

    printf( "Please enter the number k you want to find")scanf("%d"&k);

    for(int i=0;i<10;i++)

  8. Anonymous users2024-02-04

    Each while loop tests a round of array inputs, then printf("%d %d",max,loc);

    put it in while, otherwise it won't be printed.

    printf("%d %d",max,loc);

    return 0;

  9. Anonymous users2024-02-03

    Do I have to use a template?

    For struct element lookups, you might use to compare based on a few of them, or all of them.

    So it's best to write a function specifically to find it.

    For example, int find(struct stu *array, int value).

    This one is looking for m.

    If the elements found for a struct are fixed, such as a value lookup m, or only if all elements have equal values.

    You can override the operator ==

  10. Anonymous users2024-02-02

    "The struct I define is.

    struct stu c[10]=;”

    If there is a problem with the definition, the result will be only c[0]=, gone.

  11. Anonymous users2024-02-01

    #include

    using namespce std;

    int find(int num,int n,int x){for(int i=0;I can't find this data in i! "The Number of Data in a Group Edition: Rights";

    cin>>n;

    int num[n];

    int x;

    cout<<"Please enter"<>num[i];

    cout<<"Please enter the data you are looking for x:";

    cin>>x;

    cout<<"The position of data x in the array is:"<

Related questions
7 answers2024-06-06

In the whole main function, only this one variable, whether it is the first for or the second for, is the same i, the second for will have i=-1, in the case of i= -1, and printf("%d ",a[i]);Statement. So fear not! When there is no second for the case: >>>More

5 answers2024-06-06

Ok, here's the **:

#include >>>More

6 answers2024-06-06

Bubbling sorting, fractions into an array, names into a two-dimensional string, the first dimension of the string corresponds to the subscript of the array, and the sorting is exchanged once, and the exchange can be achieved by a buffered string t, using strcpy (similar to the assignment of variables), for example. >>>More

9 answers2024-06-06

This program is the application of modularity, the first two subroutines getline function, copy function as the modulated function, its function is to read a line into s and return its length and copy from to to, the main function by calling these two functions to achieve the purpose. After understanding the role of the modulated function, first analyze the main tonal function, while((len = getline(line,maxline)) 0) is to read the input line into the line and assign the length returned to len, when there is an input that is len>0, then judge whether the length is the maximum value, mark the line if it is satisfied, and copy the line to longest, and so on until the output line with the largest length is no longer input.