Savelyev_Vyacheslav

Laba_3 Cu

May 31st, 2020 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <cstdlib>
  4. #include <cmath>
  5. //check via the compiller -> https://repl.it/repls/DefiantHappyAutosketch#main.c
  6. ///////////////////////////////////////////////////////////////////
  7. // function sort max to min
  8. void Sort__from__max__to__min(int *arr, int (*size))
  9. {
  10.   int max, tochka__zameny; // peremanye
  11.   for (int i = 0; i < (*size) - 1; i++)
  12.   {max = i;
  13.     // poisk max znacheniay
  14.     for (int j = max + 1; j < (*size); j++)  //from j to (*size) ostatoc massiva ne otsortirovannyi
  15.     {
  16.       if (arr[j] > arr[i])
  17.         max = j;      
  18.     }
  19.     tochka__zameny = arr[i];      // zmana mestamy massiva
  20.     arr[i] = arr[max];
  21.     arr[max] = tochka__zameny;
  22.   }
  23. }
  24. ///////////////////////////////////////////////////////////////////
  25. // sozdanie massiva
  26. void Make_massiv_random (int *a_arr, int *total_a_element)  
  27. {
  28.  printf("\n Massiv do sortirivki \n");
  29.   for (int i = 0; i < (*total_a_element); i++)
  30.   {  
  31.  // scanf("%d ", &a_arr[i]); //ruchoi vvod
  32. a_arr[i]=pow( (-1),(rand() %  2)  )*(rand() %  13) ; //randomnyi vvod
  33. printf("%d  ", a_arr[i]);  
  34.   }    
  35. }
  36. ///////////////////////////////////////////////////////////////////
  37. ///////////////////////////////////////////////////////////////////
  38. void Uslovie__varianta (int *a_arr, int *total_a_element)  
  39. {
  40.  printf("\n Chisla iz uslovia \n");
  41.   for (int i = 0; i < (*total_a_element); i++)
  42.   {    int Uslovie;
  43.  
  44.      if (((a_arr[i-1]<a_arr[i])&&(a_arr[i]>a_arr[i+1]))) {
  45.         Uslovie++;           printf("%d  ", a_arr[i]);
  46.      }
  47.   }
  48.    
  49. }
  50. ///////////////////////////////////////////////////////////////////
  51.  
  52.  
  53. int main()
  54. {  
  55. int  total_a_element=0;
  56. printf ("Enter size of array total_a_element  _________  ");
  57. scanf("%d", &total_a_element);
  58. int *a_arr=new int[total_a_element]; //  chislo elementov
  59.  
  60.  
  61.  
  62. Make_massiv_random (a_arr, &total_a_element)  ; // zapusk massiva
  63. Uslovie__varianta (a_arr, &total_a_element);
  64.  
  65.  
  66. //kogda v massive mnogo povtorenii tsikl zapustim povtorno
  67.   for (int i = 0; i<total_a_element; i++)  {
  68.  {
  69.     Sort__from__max__to__min(a_arr, &total_a_element);  // zapusk function sortirovki
  70.         }
  71.   }
  72.  
  73.  
  74.      printf("\n \n Massiv posle sortirivki  \n"); //pechat
  75.   for (int i = 0; i<total_a_element; i++)  {
  76.      printf("%d  ", a_arr[i]); // massiv posle sotirovki
  77.   }
  78.    
  79.   getchar(); getchar();
  80.   printf("\n a_arr memory is deleted;");
  81.   printf(" - - - \n");
  82.   delete[] a_arr;
  83.  
  84.  
  85.   return 0;
  86. }
Add Comment
Please, Sign In to add comment