Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Solution to homework assignment S
- * Introduction to programming course
- * Faculty of Mathematics and Informatics of Sofia University
- * Winter semester 2020/2021
- *
- * @author Anelia Keranova
- * @idnumber 7MI0600055
- * @task 2
- * @compiler VC
- *
- */
- #include <iostream>
- using namespace std;
- int sum(int* arr, int s, int j) {
- int res = 0;
- for (int i = s; i <= j; i++) {
- res = res + arr[i];
- }
- return res;
- }
- int subArray(int* arr, int size) {
- int max = arr[0];
- for (int i = 0; i < size; i++) {
- for (int j = size; j >= i; j--) {
- int temp = sum(arr, i, j);
- if (max < temp) {
- max = temp;
- }
- }
- }
- return max;
- }
- int main()
- {
- int arr[8] = { -2, -3, 4, -1, -2, 1, 5, -3 };
- cout << subArray(arr, 8);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement