Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. inline double area(double a, double h) {
  2.     return (a * h) / 2;
  3. }
  4.  
  5. unsigned int sum(unsigned int *arr, size_t size) {
  6.     if (size > 0)
  7.         return arr[size - 1] + sum(arr, size - 1);
  8.     return 0;
  9. }
  10.  
  11. unsigned int sum(unsigned int first, unsigned int step, unsigned int count) {
  12.     if (count) {
  13.         first += step;
  14.         return first + sum(first, step, count - 1);
  15.     }
  16.     return 0;
  17. }
  18.  
  19. unsigned int sum(unsigned int first, unsigned int step, unsigned int count) {
  20.     if (count) {
  21.         first += step;
  22.         return first + sum(first, step, count - 1);
  23.     }
  24.     return 0;
  25. }
  26.  
  27. float sum(float first, float step, unsigned int count) {
  28.     if (count) {
  29.         first += step;
  30.         return first + sum(first, step, count - 1);
  31.     }
  32.     return 0;
  33. }
  34.  
  35. double sum(double first, double step, unsigned int count) {
  36.     if (count) {
  37.         first += step;
  38.         return first + sum(first, step, count - 1);
  39.     }
  40.     return 0;
  41. }
  42.  
  43. template<class T, size_t SIZE = 0>
  44. void maximum(T arr[SIZE]) {
  45.     size_t maxi = 0;
  46.    
  47.     for (size_t i = 0; i < SIZE; ++i) {
  48.         if (arr[i] > arr[maxi])
  49.             maxi = i;
  50.     }
  51.  
  52.     T t = arr[0];
  53.     arr[0] = arr[maxi];
  54.     arr[maxi] = t;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement