Advertisement
epidzhx

Untitled

Dec 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. int main() {
  7.     setlocale(LC_ALL, "rus");
  8.     int *a;
  9.     int n = 10;
  10.     a = (int*)malloc((n-1) * sizeof(int));
  11.     for (int i = 0; i < n-1; i++)
  12.         scanf("%d ", &a[i]);
  13.     int *mx = &a[0], mxi, *mn = &a[0], mni;
  14.    
  15.     for (int i = 0; i < n - 1; i++) {
  16.         if (a[i] > *mx) {
  17.             mx = &a[i];
  18.             mxi = i;
  19.         }
  20.     }
  21.    
  22.     for (int i = 0; i < n - 1; i++) {
  23.         if (a[i] < *mn) {
  24.             mn = &a[i];
  25.             mni = i;
  26.         }
  27.     }
  28.    
  29.     int t = *mx;
  30.     a[mxi] = *mn;
  31.     a[mni] = t;
  32.    
  33.     for (int i = 0; i < n; i++)
  34.         printf("%d ", a[i]);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement