Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <cstdlib>
  5. #include <time.h>
  6. #include <string>
  7. #include <math.h>
  8.  
  9. using namespace std;
  10.  
  11. void poteg(int a, int b) {
  12.  
  13. cout << "Poteg : " << pow(a,b) << endl;
  14. }
  15.  
  16. void hey(string d) {
  17.  
  18. cout << " YOUR NAME IS : " << endl;
  19. cout <<d<< endl;
  20. }
  21.  
  22. void silnia(int f1) {
  23.  
  24. int s;
  25. s = f1;
  26. long long silnia = 1;
  27.  
  28. for (int i = 1; i <= s; i++)
  29. silnia *= i;
  30.  
  31. cout << silnia << endl;
  32. }
  33.  
  34. void quick_sort(int *tab, int lewy, int prawy)
  35. {
  36. if (prawy <= lewy) return;
  37.  
  38. int i = lewy - 1, j = prawy + 1,
  39. pivot = tab[(lewy + prawy) / 2];
  40.  
  41. while (1)
  42. {
  43.  
  44. while (pivot>tab[++i]);
  45.  
  46.  
  47. while (pivot<tab[--j]);
  48.  
  49.  
  50. if (i <= j)
  51.  
  52. swap(tab[i], tab[j]);
  53. else
  54. break;
  55. }
  56.  
  57. if (j > lewy)
  58. quick_sort(tab, lewy, j);
  59. if (i < prawy)
  60. quick_sort(tab, i, prawy);
  61. }
  62.  
  63. int main()
  64. {
  65. int a;
  66. do {
  67.  
  68.  
  69. cout << " Ello ! " << endl;
  70. cout << " 1. Poteg , 2. Przywitaj, 3. Silnia, 4. Sortuj, 5. Zakoncz" << endl;
  71. cin >> a;
  72.  
  73.  
  74. switch (a)
  75. {
  76. case 1:
  77. {
  78. int first = 0;
  79. int second = 0;
  80. cout << " Podaj liczby " << endl;
  81. cin >> first;
  82. cin >> second;
  83. poteg(first, second);
  84. break;
  85. }
  86.  
  87. case 2:
  88. {
  89. string d;
  90. cout << " Your Name ! " << endl;
  91. cin >> d;
  92. hey(d);
  93. break;
  94. }
  95.  
  96. case 3:
  97. {
  98. int f1;
  99. cout << " Podaj liczby" << endl;
  100. cin >> f1;
  101.  
  102. silnia(f1);
  103. break;
  104. }
  105.  
  106. case 4:
  107. {
  108. int *tab, n;
  109.  
  110.  
  111. cin >> n;
  112. tab = new int[n];
  113.  
  114. for (int i = 0; i < n; i++)
  115. cin >> tab[i];
  116.  
  117. quick_sort(tab, 0, n - 1);
  118.  
  119.  
  120. for (int i = 0; i < n; i++)
  121. cout << tab[i] << " ";
  122.  
  123. cin.ignore();
  124. cin.get();
  125.  
  126. break;
  127.  
  128.  
  129.  
  130. }
  131.  
  132. case 5:
  133. {
  134.  
  135. cout << " KONIEC " << endl;
  136. return 0;
  137. }
  138.  
  139. }
  140. } while (a != 5);
  141.  
  142.  
  143. system("pause");
  144. return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement