/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <limits.h>
int main()
{
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);
// Find the maximum
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:
temp = array[max_index-1];
for (int i=max_index-1; i>0; i--)
array[i] = array[i-1];
array[0] = temp;
// print the results
for (int i=0; i<array_size; i++)
printf("%s%d",i==0?"":", ",array[i]);
puts("");
return 0;
}