Petro_zzz

first_function

Mar 25th, 2024
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // тут ваша функция "сумма двух чисел"
  6.  
  7. double my_sum(double x, double y) {
  8.     return x + y;
  9. }
  10.  
  11.  
  12. int get_rand(int a, int b) {
  13.     return rand() % (b - a + 1) + a;
  14. }
  15.  
  16. void show_hello() {
  17.     cout << "Hello" << endl;
  18. }
  19.  
  20. double my_comp(double x) {
  21.     return (x == 0) ? 0 : (x < 0) ? -1 : 1;
  22.     //return (x > 0) ? 1 : (x < 0) ? -1 : 0;
  23. }
  24.  
  25. int get_max(int x, int y) {
  26.     int res = x;
  27.     if (x < y)
  28.         res = y;
  29.     return res;
  30.  
  31.     // return (x > y) ? x: y;
  32. }
  33.  
  34. void task0() {
  35.     cout << my_sum(5, 8) << endl;
  36.     cout << 5 + 8 << endl;
  37.  
  38.     int t = my_sum(15, 8);
  39.     cout << t << endl;
  40.  
  41.     int val = 5;
  42.     t = my_sum(val, val);
  43.     cout << t << endl;
  44.  
  45.     cout << "-----------------------" << endl;
  46.  
  47.     for (int k = 0; k < 10; ++k)
  48.         cout << get_rand(-10, 10) << endl;
  49.  
  50.     cout << "-----------------------" << endl;
  51.  
  52.     for (int k = 0; k < 10; ++k)
  53.         cout << get_rand(-10, 10) << endl;
  54. }
  55.  
  56. int get_cube(int x) {
  57.     //cout << "CUBE" << endl;
  58.     //return x * x * x;
  59.     return pow(x, 3);
  60. }
  61.  
  62. bool is_prime_bad(int x) {
  63.     const int n = 11;
  64.     int arr[n]{ 1,2,3,5,7,9,11,13,17,19,23 };
  65.     for (int k = 0; k < n; ++k) {
  66.         if (x == arr[k])
  67.             return true;
  68.     }
  69.     return false;
  70. }
  71.  
  72. bool is_prime(int x) {
  73.     if (x <= 0)
  74.         return false;
  75.     for (int v = 2; v < sqrt(x); ++v) {
  76.         if (x % v == 0)
  77.             return false;
  78.     }
  79.     return true;
  80. }
  81.  
  82. unsigned long long factorial(int x) {
  83.     unsigned long long res = 1;
  84.     if (x < 2)
  85.         return res;
  86.     while (x > 1) {
  87.         res *= x;
  88.         x -= 1;
  89.     }
  90.     return res;
  91. }
  92.  
  93. void show_rectangle(int n, int k) {
  94.     for (int y = 0; y < n; y++) {
  95.         for (int x = 0; x < k; x++) {
  96.             if (x == 0 || y == 0 ||
  97.                 x == k - 1 || y == n - 1)
  98.                 cout << "+";
  99.             else
  100.                 cout << " ";
  101.         }
  102.         cout << endl;
  103.     }
  104. }
  105.  
  106.  
  107. int main() {
  108.     srand(time(NULL));
  109.     // адрес а не вызов
  110.  
  111.     cout << my_comp(-10) << " "
  112.          << my_comp(11) << " "
  113.          << my_comp(0) << endl;
  114.  
  115.  
  116.     cout << get_max(-100, 100) << endl;
  117.  
  118.     cout << get_rand << endl;
  119.  
  120.     cout << is_prime(17) << endl;
  121.     cout << factorial(10) << endl;
  122.     show_rectangle(7, 14);
  123.  
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment