uses crt; var a, b, c, n, i, j :integer; s :array [1..10000] of integer; begin clrscr; writeln ('Vvedite razmer masiva'); read (n); writeln ('Vvedite chislo X'); read (a); for i:=1 to n do begin writeln ('Vvedit s[', i, '] element'); read (s[i]); end; for i:=1 to n do for j:=1 to n-1 do if s[j]<s[j+1] then begin b:=s[j]; s[j]:=s[j+1]; s[j+1]:=b; end; for i:=1 to n do begin write (s[i], ' '); if s[i]=a then inc (c); end; writeln; if c>0 then writeln ('3adanoe chislo prisytstvyet') else writeln('3adanoe chislo otsytstvyet'); end.
#include <stdio.h>
#include <malloc.h>
//сортировка вставками
void InsertionSort(int n, int mass[])
{
int newElement, location;
for (int i = 1; i < n; i++)
{
newElement = mass[i];
location = i - 1;
while(location >= 0 && mass[location] > newElement)
{
mass[location+1] = mass[location];
location = location - 1;
}
mass[location+1] = newElement;
}
}
int main()
{
//ввод N
int N;
printf("Input N: ");
scanf("%d", &N);
//выделение памяти под массив
int* mass;
mass = (int *)malloc(N * sizeof(int));
//ввод элементов массива
printf("Input the array elements:\n");
for (int i = 0; i < N; i++)
scanf("%d", &mass[i]);
//сортировка вставками
InsertionSort(N, mass);
//вывод отсортированного массива на экран
printf("Sorted array:\n");
for (int i = 0; i < N; i++)
printf("%d ", mass[i]);
printf("\n");
//освобождение памяти
free(mass);
return 0;
}