Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <cstdlib>
- #include <cmath>
- //check via the compiller -> https://repl.it/repls/DefiantHappyAutosketch#main.c
- ///////////////////////////////////////////////////////////////////
- // function sort max to min
- void Sort__from__max__to__min(int *arr, int (*size))
- {
- int max, tochka__zameny; // peremanye
- for (int i = 0; i < (*size) - 1; i++)
- {max = i;
- // poisk max znacheniay
- for (int j = max + 1; j < (*size); j++) //from j to (*size) ostatoc massiva ne otsortirovannyi
- {
- if (arr[j] > arr[i])
- max = j;
- }
- tochka__zameny = arr[i]; // zmana mestamy massiva
- arr[i] = arr[max];
- arr[max] = tochka__zameny;
- }
- }
- ///////////////////////////////////////////////////////////////////
- // sozdanie massiva
- void Make_massiv_random (int *a_arr, int *total_a_element)
- {
- printf("\n Massiv do sortirivki \n");
- for (int i = 0; i < (*total_a_element); i++)
- {
- // scanf("%d ", &a_arr[i]); //ruchoi vvod
- a_arr[i]=pow( (-1),(rand() % 2) )*(rand() % 13) ; //randomnyi vvod
- printf("%d ", a_arr[i]);
- }
- }
- ///////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- void Uslovie__varianta (int *a_arr, int *total_a_element)
- {
- printf("\n Chisla iz uslovia \n");
- for (int i = 0; i < (*total_a_element); i++)
- { int Uslovie;
- if (((a_arr[i-1]<a_arr[i])&&(a_arr[i]>a_arr[i+1]))) {
- Uslovie++; printf("%d ", a_arr[i]);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////
- int main()
- {
- int total_a_element=0;
- printf ("Enter size of array total_a_element _________ ");
- scanf("%d", &total_a_element);
- int *a_arr=new int[total_a_element]; // chislo elementov
- Make_massiv_random (a_arr, &total_a_element) ; // zapusk massiva
- Uslovie__varianta (a_arr, &total_a_element);
- //kogda v massive mnogo povtorenii tsikl zapustim povtorno
- for (int i = 0; i<total_a_element; i++) {
- {
- Sort__from__max__to__min(a_arr, &total_a_element); // zapusk function sortirovki
- }
- }
- printf("\n \n Massiv posle sortirivki \n"); //pechat
- for (int i = 0; i<total_a_element; i++) {
- printf("%d ", a_arr[i]); // massiv posle sotirovki
- }
- getchar(); getchar();
- printf("\n a_arr memory is deleted;");
- printf(" - - - \n");
- delete[] a_arr;
- return 0;
- }
Add Comment
Please, Sign In to add comment