Question
CAN SOMEONE GIVE AN IN-DEPTH EXPLANATION OF WHAT'S HAPPENING IN THIS CODE LINE BY LINE ? // CPP program to find if we can get
CAN SOMEONE GIVE AN IN-DEPTH EXPLANATION OF WHAT'S HAPPENING IN THIS CODE LINE BY LINE ? // CPP program to find if we can get given // sum using elements of given array. #include
void check(int arr[], int N) { ispossible[0] = 1; sort(arr, arr + N);
for (int i = 0; i < N; ++i) { int val = arr[i]; // if it is already possible if (ispossible[val]) continue; // make 1 to all it's next elements for (int j = 0; j + val < MAX; ++j) if (ispossible[j]) ispossible[j + val] = 1; } }
// Driver code int main() { int arr[] = { 4,2 }; int N = sizeof(arr) / sizeof(arr[0]); check(arr, N); int x = 100; if (ispossible[x]) cout << x << " is possible."; else cout << x << " is not possible."; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started