Const n = 5; var i: integer; a: array[1..n * 2 + 1] of integer; begin writeln('исходный массив: '); for i : = 1 to 2 * n do begin a[i] : = random(99) + 1; write(a[i] : 5); end; for i : = 2 * n + 1 downto n + 1 do a[i] : = a[i - 1]; a[n + 1] : = 0; writeln(); writeln('полученный массив: '); for i : = 1 to 2 * n + 1 do write(a[i] : 5); end.
см.пояснение
Объяснение:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int n=499;
int main() {
srand(time(0));
int arr[n],min=100,max=-100,iter=0,mediana;
for (int i=0;i<n;i++){
arr[i]=rand()%200-100;
if (min>arr[i])
min=arr[i];
if (max<arr[i])
max=arr[i];
}
for (int i=0;i<n;i++){
if(arr[i]==max)
iter++;
}
int swap;
for (int i=0;i<n-1;i++){
for (int j=i+1;j<n;j++){
if (arr[i]>arr[j]){
swap=arr[i];
arr[i]=arr[j];
arr[j]=swap;
}
}
}
mediana=n/2+1;
mediana=arr[mediana];
cout<<"min = "<<min<<endl;
cout<<"max = "<<max<<" povtorov: "<<iter<<endl;
cout<<"mediana = "<<mediana;
return 0;
}