Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
641 B
2
Indexable
#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    long long int arr[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%lld",&arr[i]);
    }
    int min=arr[0],max=arr[0],index_max,index_min,temp;
    for (int i = 1; i < n; i++)
    {
        if (arr[i]>max)
        {
            max=arr[i];
            index_max=i;
        }
        if (arr[i]<min)
        {
            min=arr[i];
            index_min=i;
        } 
    }
    
    arr[index_min]=max;
    arr[index_max]=min;
    
    for (int i = 0; i < n; i++)
    {
        printf("%lld ",arr[i]);
    }
    
    return 0;
}