Advertisement
Guest User

Pr 9 Array

a guest
Nov 22nd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>  // Для srand()
  6. using namespace std;
  7.  
  8. void Rand_Arr(int a[], int len_a)
  9. {
  10. // Заполнение массива.
  11. // Функция rand() возвращает псевдослучайное целое в диапазоне от
  12. // 0 to RAND_MAX (32767).
  13. for (int i = 0; i < len_a; i++)
  14.     a[i] = (double)rand( ) / (RAND_MAX + 1) * 50 - 25;
  15.         // Диапазон -25 - +25
  16. }
  17. void Print_Arr (int a[], int len_a)      // Имя (int a, int b)
  18. { //Вывод массива
  19. cout << "\nIs Array:\n";
  20. for (int i=0; i<len_a; i++)
  21.     cout << " " << a[i];
  22. cout << endl;
  23. }
  24. void Print_Arr (float a[], int len_a)
  25. { //Вывод массива
  26.     cout << "\nIs Array:\n";
  27.     for (int i = 0; i<len_a; i++)
  28.         cout << " " << a[i];
  29.     cout << endl;
  30. }
  31. void Input_Arr(int a[], int & len_a)
  32. { //Ввод массива
  33.    cout << "\nInput length of Array:\n";
  34.    cin >> len_a;    // Сколько данных.
  35.    cout <<"\nInput " << len_a << " elements of Array:\n";
  36.    for (int i=0; i<len_a; i++)
  37.       cin >> a[i];
  38. }
  39.  
  40. // Среднее арифметическое.
  41. float sum(double a[], int len)
  42. {
  43. double S=0;
  44. // Суммирование элементов
  45. for (int i=0;i<len;i++)
  46.     S+=a[i];
  47. return  S ;
  48. }
  49. // Примеры функций обработки массивов.
  50. // 1. Проверить, упорядочен ли.
  51. int YesUp(int a[], int n)
  52. { // Думаем, что упорядочен.
  53. for (int i = 0; i<n - 1; i++)
  54.     if (a[i + 1] >= a[i])
  55.         return 0;
  56. return 1;
  57. }
  58. int YesDown(int a[], int n)
  59. { // Думаем, что упорядочен.
  60.     for (int i = 0; i<n - 1; i++)
  61.         if (a[i + 1] <= a[i])
  62.             return 0;
  63.     return 1;
  64. }
  65. // 2. Минимакс находит и возвращает номер наименьшего элемента.
  66. int Month(double a[], int n)
  67. {   // Номер наименьшего.
  68. int min=0;
  69. for (int i=1; i<n; i++)
  70.     if (a[i]>a[min])
  71.         min=i;
  72. return min;
  73. }
  74. // Изменение длины массива. ! контроль выхода.
  75. // 3. Удаление. Удаление наименьшего элемента массива.
  76.  
  77. // Параллельные массивы.
  78. // Найти точку, наиболее удаленную от начала координат.
  79. // Функция вернет ее номер.
  80. int Point(float x[], float y[], int Count)
  81. {
  82.     int maxn = 0;
  83.     float R = sqrt(x[0] * x[0] + y[0] * y[0]);
  84.     for(int i=1; i<Count; i++)
  85.         if (sqrt(x[i] * x[i] + y[i] * y[i]) > R)
  86.         {
  87.             maxn = i;
  88.             R = sqrt(x[i] * x[i] + y[i] * y[i]);
  89.         }
  90.     return maxn;
  91. }
  92.  
  93. struct Stud
  94. {
  95.     std::string Name;
  96.     std::string NickName;
  97.     int Weigth;
  98.     int Age;
  99. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement