Advertisement
2607

seq

Sep 30th, 2021
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int n;
  6.     int i = 0;
  7.     int *arr = malloc(sizeof(int));
  8.     while (n!= -1) {
  9.         scanf("%d", &n);
  10.         i++;
  11.         arr = realloc(arr, i*sizeof(int));
  12.         arr[i-1] = n;
  13.     }
  14.     int min = arr[0];
  15.     int min_j = 0;
  16.     int max = arr[0];
  17.     int max_j = 0;
  18.     for (int j = 0; j < i-1; ++j) {
  19.         if (arr[j] < min) {
  20.             min = arr[j];
  21.             min_j = j;
  22.         }
  23.         if (arr[j] > max) {
  24.             max = arr[j];
  25.             max_j = j;
  26.         }
  27.     }
  28.     for (int j = 0; j < i-1; ++j) {
  29.         if (j == min_j)
  30.             printf("%d ", max);
  31.         else if (j == max_j)
  32.             printf("%d ", min);
  33.         else
  34.             printf("%d ", *(arr+j));
  35.     }
  36.     printf("\n");
  37.     for (int j = 0; j < i-1; ++j) {
  38.    
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement