[ad_1]
Here is the code I’ve tried solving… but couldn’t get the right output.
I want the input to be as all negative integers. And I would like to solve it using Kadane’s Algorithm.
Help me solve this.
Thank you.
#include <stdio.h>
int maxsubstring() {
int arr[25], n;
int maxSum = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == -1) {
maxSum = -1;
} else {
sum = sum + arr[i];
if (sum > maxSum) {
maxSum = sum;
}
}
}
}
int main() {
int arr[25], n;
printf("Enter the Range of Array Elements: ");
scanf("%d", &n);
printf("Enter The Array Elements: ");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
return maxsubstring;
}
[ad_2]