Advertisement
peterzig

dla Ęśąćż tablica

Oct 21st, 2020
1,962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #define  _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int Count(double* arr, const int size)
  7. {
  8.     int temp = 0;
  9.     for (int i = 0; i < size; ++i)
  10.     {
  11.         if (arr[i] == int(arr[i]))
  12.         {
  13.             temp++;
  14.         }
  15.     }
  16.     return temp;
  17. }
  18.  
  19. double Min(double* arr, const int size)
  20. {
  21.     double min = arr[0];
  22.     for (int i = 0; i < size; i++)
  23.     {
  24.         if (arr[i] < min)
  25.         {
  26.             min = arr[i];
  27.         }
  28.     }
  29.     return min;
  30. }
  31.  
  32. double Max(double* arr, const int size)
  33. {
  34.     double max = arr[0];
  35.     for (int i = 0; i < size; i++)
  36.     {
  37.         if (arr[i] > max)
  38.         {
  39.             max = arr[i];
  40.         }
  41.     }
  42.     return max;
  43. }
  44.  
  45. void Sort(double* arr, const int size)
  46. {
  47.     if (arr && size > 0)
  48.     {
  49.         double xx;
  50.         int j;
  51.         for (int i = size - 2; i >= 0; --i)
  52.         {
  53.             xx = arr[i];
  54.             j = i + 1;
  55.             while (j < size && xx > arr[j])
  56.             {
  57.                 arr[j - 1] = arr[j];
  58.                 j++;
  59.             }
  60.             arr[j - 1] = xx;
  61.         }
  62.     }
  63. }
  64.  
  65. void PrintTab(double* arr, const int size)
  66. {
  67.     printf("tablica = [");
  68.     for (int i = 0; i < size; i++)
  69.     {
  70.         printf("%.2f ,", arr[i]);
  71.     }
  72.     printf("]\n");
  73. }
  74.  
  75. int main()
  76. {
  77.     int size;
  78.     printf("Podaj wymiar tablicy: ");
  79.     scanf("%d", &size);
  80.  
  81.     double* tab = new double[size];
  82.  
  83.     for (int i = 0; i < size; i++)
  84.     {
  85.         printf("Podaj %d element tablicy: ", i + 1);
  86.         scanf("%lf", &tab[i]);
  87.         //cout << "Podaj " << i + 1 << " element tablicy: ";
  88.         //cin >> tab[i];
  89.     }
  90.  
  91.     PrintTab(tab, size);
  92.     printf("Maximum: %lf \n", Max(tab, size));
  93.     printf("Minimum: %lf \n", Min(tab, size));
  94.     printf("Ilosc liczb calkowitych: %d \n", Count(tab, size));
  95.     Sort(tab, size);
  96.     PrintTab(tab, size);
  97.     delete[] tab;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement