This repository was archived by the owner on Apr 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_functions.cpp
More file actions
108 lines (90 loc) · 2.19 KB
/
my_functions.cpp
File metadata and controls
108 lines (90 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "my_functions.h"
int max_square(int arr[], int length) {
int max = INT_MIN;
for (int i = 0; i < length; i++) {
if (std::pow(arr[i], 2) > max) {
max = std::pow(arr[i], 2);
}
}
return max;
}
int max_cube(int arr[], int length)
{
int max = INT_MIN;
for (int i = 0; i < length; i++) {
if (std::pow(arr[i], 3) > max) {
max = std::pow(arr[i], 3);
}
}
return max;
}
int min_index(int a[], int n) {
int min_val = a[0];
int min_index_val = 1;
for (int i = 2; i <= n; i++) {
if (a[i - 1] * i < min_val * min_index_val) {
min_val = a[i - 1];
min_index_val = i;
}
}
return min_val * min_index_val;
}
int min_sum(int a[], int n) {
int min_val = a[0] + a[1];
for (int i = 2; i < n; i++) {
if (a[i - 1] + a[i] < min_val) {
min_val = a[i - 1] + a[i];
}
}
return min_val;
}
int max_product(int a[], int n) {
int max_val = a[0];
int prod = a[0];
for (int i = 1; i < n; i++) {
prod *= a[i];
if (prod > max_val) {
max_val = prod;
}
if (a[i] == 0) {
prod = 1;
}
}
return max_val;
}
int count_even(int a[], int n) {
int count = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
count++;
}
}
return count;
}
int count_double_odd(int a[], int n) {
int count = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 1 && a[i] * 2 % 2 == 0) {
count++;
}
}
return count;
}
int count_squares(int arr[], int length) {
int count = 0;
for (int i = 0; i < length; i++) {
if (arr[i] >= 0 && std::sqrt(arr[i]) == std::floor(std::sqrt(arr[i]))) {
count++;
}
}
return count;
}
int count_odd_squares(int arr[], int length) {
int count = 0;
for (int i = 0; i < length; i++) {
if (arr[i] % 2 != 0 && arr[i] >= 0 && std::sqrt(arr[i]) == std::floor(std::sqrt(arr[i]))) {
count++;
}
}
return count;
}