Advertisement
Petro_zzz

функции2_main

Mar 27th, 2024
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #pragma once
  2.  
  3. using namespace std;
  4.  
  5. void show_arr(int size, int arr[]) {
  6.     for (int k = 0; k < size; k++) {
  7.         cout << arr[k] << " ";
  8.     }
  9.     cout << endl;
  10. }
  11.  
  12. void show_arr(int size, double arr[]) {
  13.     for (int k = 0; k < size; k++) {
  14.         cout << arr[k] << " ";
  15.     }
  16.     cout << endl;
  17. }
  18.  
  19. int gen_rand(int a, int b) {
  20.     return rand() % (b + 1 - a) + a;
  21. }
  22.  
  23. void gen_randarr(int size, int arr[], int a, int b) {
  24.     for (int k = 0; k < size; k++) {
  25.         arr[k] = gen_rand(a, b);
  26.     }
  27. }
  28.  
  29. /// <summary>
  30. /// Calc area for trapetc
  31. /// </summary>
  32. /// <param name="a">side of trapec</param>
  33. /// <param name="b">side if trapec</param>
  34. /// <param name="h">height of trapec</param>
  35. /// <returns>Area of trapec</returns>
  36. double calc_area(double a, double b, double h) {
  37.     return 0.5 * (a + b) * h;
  38. }
  39.  
  40. bool is_prime(int x) {
  41.     if (x <= 0)
  42.         return false;
  43.     for (int v = 2; v <= sqrt(x); ++v) {
  44.         if (x % v == 0)
  45.             return false;
  46.     }
  47.     return true;
  48. }
  49.  
  50.  
  51. void show_minmax(int size, int arr[]) {
  52.     int max = arr[0];
  53.     int min = arr[0];
  54.     int idmax = 0;
  55.     int idmin = 0;
  56.  
  57.     for (int k = 1; k < size; k++) {
  58.         if (max < arr[k]) {
  59.             max = arr[k];
  60.             idmax = k;
  61.         }
  62.  
  63.         if (min > arr[k]) {
  64.             min = arr[k];
  65.             idmin = k;
  66.         }
  67.     }
  68.  
  69.     cout << "max in " << idmax + 1 << " equal " << max << endl;
  70.     cout << "min in " << idmin + 1 << " equal " << min << endl;
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement