Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- inline double area(double a, double h) {
- return (a * h) / 2;
- }
- unsigned int sum(unsigned int *arr, size_t size) {
- if (size > 0)
- return arr[size - 1] + sum(arr, size - 1);
- return 0;
- }
- unsigned int sum(unsigned int first, unsigned int step, unsigned int count) {
- if (count > 1) {
- return first + sum(first + step, step, count - 1);
- }
- return first;
- }
- float sum(float first, float step, unsigned int count) {
- if (count > 1) {
- return first + sum(first + step, step, count - 1);
- }
- return first;
- }
- double sum(double first, double step, unsigned int count) {
- if (count > 1) {
- return first + sum(first + step, step, count - 1);
- }
- return first;
- }
- template<class T, size_t SIZE = 0>
- void maximum(T arr[SIZE]) {
- size_t maxi = 0;
- for (size_t i = 0; i < SIZE; ++i) {
- if (arr[i] > arr[maxi])
- maxi = i;
- }
- T t = arr[0];
- arr[0] = arr[maxi];
- arr[maxi] = t;
- }
- int main()
- {
- unsigned int arr[] = { 1, 2, 3 };
- std::cout << area(10., 5.) << std::endl;
- std::cout << sum(arr, 3) << std::endl;
- std::cout << sum(5U, 1U, 5U) << std::endl;
- std::cout << sum(0.5f, 0.1f, 5) << std::endl;
- std::cout << sum(0.5, 0.1, 5) << std::endl;
- maximum<unsigned int, 3>(arr);
- std::cout << arr[0] << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement