What Is The Output Of The Following Codep Pre Langc #2163
What is the output of the following code?</p> <pre><code class="language-c"> #include<stdio.h> #include<limits.h> int max_num(int a, int b) { if(a > b) return a; return b; } int kadane_algo(int *arr, int len) { int ans, sum, idx; ans =0; sum =0; for(idx =0; idx < len; idx++) { sum = max_num(0,sum + arr[idx]); ans = max_num(sum,ans); } return ans; } int max_sum_rectangle(int arr[][5],int row,int col) { int left, right, tmp[row], mx_sm = INT_MIN, idx, val; for(left = 0; left < col; left++) { for(right = left; right < col; right++) { if(right == left) { for(idx = 0; idx < row; idx++) tmp[idx] = arr[idx][right]; } else { for(idx = 0; idx < row; idx++) tmp[idx] += arr[idx][right]; } val = kadane_algo(tmp,row); if(val > mx_sm) mx_sm = val; } } return mx_sm; } int main() { int arr[2][5] ={{1, 2, -1, -4, -20}, {-4, -1, 1, 7, -6}}; int row = 2, col = 5; int ans = max_sum_rectangle(arr,row,col); printf("%d",ans); return 0; }</code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Dynamic Programming - Maximum Sum Rectangle in a 2D Matrix - Quiz No.2.
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes