Question 8152 – Computer-Organization
May 28, 2024Question 14945 – DSSSB TGT 2017
May 28, 2024Question 10746 – C-Programming
Consider the C program given below:
#include int main () { int sum = 0, maxsum = 0, i, n = 6; int a [] = {2, -2, -1, 3, 4, 2}; for (i = 0; i < n; i++) { if (i == 0 || a [i] < 0 || a [i] < a [i - 1]) { if (sum > maxsum) maxsum = sum; sum = (a [i] > 0) ? a [i] : 0; } else sum += a [i]; } if (sum > maxsum) maxsum = sum ; printf ("%dn", maxsum); }
What is the value printed out when this program is executed?
Correct Answer: C
Question 13 Explanation:
The algorithm is for finding the maximum sum of the monotonically increasing continuous sequence of positive numbers in the array. So, output will be 3+4 = 7.
9
8
7
6
Subscribe
Login
0 Comments