Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int n;
- int i = 0;
- int *arr = malloc(sizeof(int));
- while (n!= -1) {
- scanf("%d", &n);
- i++;
- arr = realloc(arr, i*sizeof(int));
- arr[i-1] = n;
- }
- int min = arr[0];
- int min_j = 0;
- int max = arr[0];
- int max_j = 0;
- for (int j = 0; j < i-1; ++j) {
- if (arr[j] < min) {
- min = arr[j];
- min_j = j;
- }
- if (arr[j] > max) {
- max = arr[j];
- max_j = j;
- }
- }
- for (int j = 0; j < i-1; ++j) {
- if (j == min_j)
- printf("%d ", max);
- else if (j == max_j)
- printf("%d ", min);
- else
- printf("%d ", *(arr+j));
- }
- printf("\n");
- for (int j = 0; j < i-1; ++j) {
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement