Advertisement
Garey

Митака

Dec 22nd, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int FN[25], N;
  5. int n;
  6. void masiv()
  7. {
  8.     do {
  9.         cout << "\n Choose how many FN do u want: (no more than 25)\n";
  10.         cin >> N;
  11.     } while (N<0 || N>25);
  12.     for (int i = 0; i < N; i++)
  13.     {
  14.         cout << "\n FN[" << i + 1 << "]=";
  15.         cin >> FN[i];
  16.     }
  17. }
  18. template <class T>
  19. T bubble_sort_array(T array[], size_t array_size, bool type = false) {
  20.     for (size_t i = 0; i < array_size - 1; i++) {
  21.         for (size_t j = i + 1; j < array_size; j++)
  22.             if ((type ? (array[i] > array[j]) : (array[i] < array[j]))) {
  23.                 T temp = array[i];
  24.                 array[i] = array[j];
  25.                 array[j] = temp;
  26.             }
  27.     }
  28.  
  29.     return *array;
  30. }
  31.  
  32. void odd()
  33. {
  34.     for (int i = 0; i < 10; i++)
  35.     {
  36.         if (FN[i] % 2 == 1)
  37.             cout << FN[i] << "\n";
  38.     }
  39. }
  40. int maxi(int *ind)
  41. {
  42.     int m = FN[0];
  43.     for (int i = 1; i < N; i++)
  44.         if (m < FN[i])
  45.         {
  46.             m = FN[i]; *ind = i + 1;
  47.         }
  48.     return m;
  49. }
  50. void print(int *m, int *ind)
  51. {
  52.     for (int i = 0; i < N; i++)
  53.         cout << FN[i] << "\t";
  54.     cout << "\n \n";
  55.     cout << "\n Max=" << *m << endl;
  56.     cout << "\n Position:" << *ind << endl;
  57. }
  58. void main()
  59. {
  60.     int ch, i, max, index, F[25];
  61.     do {
  62.         cout << "\n \t Menu \n";
  63.         cout << "\n 1.Input FN (do 25) \n";
  64.         cout << "\n 2.ODD FN \n";
  65.         cout << "\n 3.Finding max FN and shows its position \n";
  66.         cout << "\n 4.Sort ascending \n";
  67.         cout << "\n 5.Shows information \n";
  68.         cout << "\n 6.Exit \n";
  69.         do { cout << "\n your choice is:"; cin >> ch; } while (ch<1 || ch>6);
  70.         switch (ch)
  71.         {
  72.         case 1:masiv(); break;
  73.         case 2:odd(); break;
  74.         case 3:max = maxi(&index); cout << "\n Max FN=" << max << "  on pos:" << index << endl; break;
  75.         case 4:
  76.             bubble_sort_array<int>(FN, N, true);
  77.             for (size_t i = 0; i < N; i++)
  78.                 cout << FN[i] << endl;
  79.             break;
  80.         case 5:print(&max, &index); break;
  81.         }
  82.     } while (ch != 6);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement