Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7.  
  8. //https://pastebin.com/AM7CGswP
  9.  
  10. //https://pastebin.com/SzwN5JKN
  11.  
  12.  
  13. //https://pastebin.com/CDzc1TXw
  14.  
  15.  
  16. void sortowanie(float t[], int n)
  17. {
  18.    //sortowanie bąbelkowe
  19.   for (int i=0; i<n-1; i++)
  20.     for (int j=i+1; j<n; j++)
  21.     {
  22.       if ( t[i] > t[j] ) {
  23.         float r = t[i];
  24.         t[i] = t[j];
  25.         t[j] = r;
  26.       }
  27.     }
  28. }
  29.  
  30.  
  31. void wyswietlanie(float t[], int n)
  32. {
  33.     for (int i=0; i<n; i++) {
  34.       cout << t[i] << " ";  
  35.     }
  36.     cout << endl;
  37. }
  38.  
  39.  
  40. void losuj(float t[], int n)
  41. {
  42.    for (int i=0; i<n; i++)
  43.    t[i] = rand() % 20 + 1;
  44. }
  45.  
  46. void losuj(float t[], int n, int zakres_min, int zakres_max)
  47. {
  48.    int zakres = zakres_max-zakres_min;
  49.    for (int i=0; i<n; i++)
  50.    t[i] = rand() % zakres + zakres_min;
  51. }
  52.  
  53.  
  54. float suma(float t[], int n)
  55. {
  56.   float s = 0;
  57.   for (int i=0; i<n; i++) {
  58.     s = s + t[i];
  59.   }  
  60.   return s;
  61. }
  62.  
  63. float mediana(float t[], int n) {
  64.   sortowanie(t,n);
  65.   return t[n/2];
  66. }
  67.  
  68.  
  69.  
  70. int main()
  71. {
  72.   //alokowanie pamięci na potrzeby tablicy
  73.  float *tab;
  74.  
  75.  int N = 100000000;
  76.  
  77.   //!!!
  78.  tab = new float[N];
  79.  
  80.  losuj(tab, N);
  81.  wyswietlanie(tab, N);
  82.  sortowanie(tab, N);
  83.  wyswietlanie(tab, N);
  84.  
  85.   //!!!
  86.  delete [] tab;
  87.  
  88.  // nieobowiązkowe
  89.  int * a;
  90.  a = new int;
  91.  cout << a << endl;
  92.  *a = 10;
  93.  cout << *a << endl;
  94.  delete a;
  95.  
  96.  system("pause");
  97.  return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement