Select the correct option to test your answer:
Computer
Miscellaneous On Data Structures
Difficulty: Medium
What will be the output for the following code? #include <stdio.h> bool func(int arr[], int n, int sum) { bool subarr[n+1][sum+1]; for (int i = 0; i <= n; i++) subarr[i][0] = true; for (int i = 1; i <= sum; i++) subarr[0][i] = false; for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if(j<arr[i-1]) subarr[i][j] = subarr[i-1][j]; if (j >= arr[i-1]) subarr[i][j] = subarr[i-1][j] || subarr[i - 1][j-arr[i-1]]; } } return subarr[n][sum]; } int main() { int arr[] = {3, 3, 4, 4, 7}; int sum = 5; int n = sizeof(arr)/sizeof(arr[0]); if (func(arr, n, sum) == true) printf("true"); else printf("false"); return 0; }
More Computer Questions
What will be the output of the following Python code snippet? print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
What will be the output of the following Python code snippet? print('HelloWorld'.istitle())
Under multiprogramming, turnaround time for short jobs is usually _____ and that for long jobs is slightly _____.
What will be the result? int i = 10; while(i++ <= 10){ i++; } System.out.print(i);
What is the output of the following code: my_dict = {'a': 1, 'b': 2} print(my_dict['a'])