Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

it is an exercice and i can't do it.help me pls.

+3 votes
asked Apr 27, 2020 by gfrve dfss (370 points) 1 flag
Enter a one-dimensional integer array. Find the largest odd item. Next, make a cyclic shift to the left of the elements standing to the right of the found maximum, and once shift the elements to the right, standing to the left of the found maximum.

2 Answers

0 votes
answered Aug 6, 2021 by Devansh Saxena (140 points)
Can you please give an example of required output !!
+1 vote
answered Jun 27, 2025 by Jerry Jeremiah (2,040 points)
edited Jun 27, 2025 by Jerry Jeremiah

A one dimsional array is:

    int array[20] = {33,86,6,38,67,18,91,5,51,20,54,94,4,9,31,17,71,80,22,14};
    int array_size = sizeof(array)/sizeof(*array);

Then you can find the maximum with:

    int max = INT_MIN, max_index = -1;
    for (int i=0; i<array_size; i++)
        if (array[i] > max) {
            max = array[i];
            max_index = i;
        }

The you can shift the items to the right of the max_index with:

    int temp = array[max_index+1];
    for (int i=max_index+1; i<array_size-1; i++)
        array[i] = array[i+1];
    array[array_size-1] = temp;

The you can shift the items to the left of the max_index with:

    int temp = array[max_index-1];
    for (int i=max_index-1; i>0; i--)
        array[i] = array[i-1];
    array[0] = temp;

You can see the whole program at https://onlinegdb.com/-2RkoUeHj

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...