-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.cpp
More file actions
41 lines (33 loc) · 878 Bytes
/
task1.cpp
File metadata and controls
41 lines (33 loc) · 878 Bytes
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
#include <iostream>
#include <climits>
int summation(int arr[], int n) {
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += arr[i];
}
return sum;
}
int maximum(int arr[], int n) {
int max_value = INT_MIN;
for (int i = 0; i < n; ++i) {
if (arr[i] > max_value) {
max_value = arr[i];
}
}
return max_value;
}
int main() {
int n;
std::cout << "Enter the length of the array (0 <= n <= ∞): ";
std::cin >> n;
int array[n];
for (int i = 0; i < n; ++i) {
std::cout << "Enter integer " << i + 1 << ": ";
std::cin >> array[i];
}
int sum_result = summation(array, n);
std::cout << "Sum of the array: " << sum_result << std::endl;
int max_result = maximum(array, n);
std::cout << "Maximum element in the array: " << max_result << std::endl;
return 0;
}