1. What will be the output of the following program?
#include<stdio.h>
int min(int x, int y) {
return (y <x)? y: x;
}
int main() {
int a[] = {-5, 9, 8,-8, -2};
int z = a[0], n=5, i=0,c=a[0];
for (i = 1;i<n; i++) {
c=min(a[i], c+a[i]);
z = min(z, c);
}
printf("%d", z);
}
Answers
Answered by
0
Answer:
-10
Explanation:
For i=1
c = min (9, 4) = 4
z = min (-5, 4) = -5
For i=2
c = min (8, 12) = 8
z = min (-5, 8) = -5
For i=3
c = min (-8, 0) = -8
z= min (-5, -8) = -8
For i=4
c= min(-2, -10) = -10
z = min (-8, -10) = -10
Hence answer = -10
Answered by
0
-10 is the required output
Explanation:
#include<stdio.h>
int min(int x, int y) {
return (y <x)? y: x;
}
int main() {
int a[] = {-5, 9, 8,-8, -2};
int z = a[0], n=5, i=0,c=a[0];
for (i = 1;i<n; i++) {
c=min(a[i], c+a[i]);
z = min(z, c);
}
printf("%d", z);
}
- -10 is the required output
hence, -10 is the correct answer.
Similar questions