...
Question 8152 – Computer-Organization
May 28, 2024
Question 14945 – DSSSB TGT 2017
May 28, 2024
Question 8152 – Computer-Organization
May 28, 2024
Question 14945 – DSSSB TGT 2017
May 28, 2024

Question 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.
A
9
B
8
C
7
D
6
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!