Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me withthis Code in C Bb Home I Chegg.com Search or ente

ID: 3840391 • Letter: C

Question

Can someone please help me withthis Code in C

Bb Home I Chegg.com Search or enter website name Apple Disney ESPN Yahoo My Blackboard Content-Blackboard Learn Student Courses Online Storage E-Portfolio Organizations & Clubs Help Name timer counts down to zero from a user supplied number. Description Displays a count down to zero from a number supplied by the user at the command line. Supports pausing and unpausing the countdown. Countdown is done by ones, one second at a time. While the program is runnng, Ctrl C will pause and unpause the countdown, by sending an appropriate signal. Typing Ctrl-1 will terminate the program. Echoing of characters is disabled while the program is running. Sample Usage timer 60 begins the countdown Hints man 3 sleep uses signals and a spinlock. Ctrl Cengages, disengages the spinlock. spinlocks while( pause true lfpause is set to true, then this while loop will iterate. When pause gets set to false, this loop gets skipped. See the attached code for a spinlock example, spinlock.cpp A 10-Point Sample Run At 57 seconds left, I hit Ctrl-C: hstalica HANK-LAPTOP /mnt/c/Users/hstalica/Desktop$ cc timer.c hstalica HANK-LAPTOP /mnt/c/Users/hstalica/Desktop$ ./a.out 60 59

Explanation / Answer

// A Naive recursive C++ program to find minimum of coins
// to make a given change V
#include<bits/stdc++.h>
using namespace std;

// m is size of coins array (number of different coins)
int minCoins(int coins[], int m, int V)
{
// base case
if (V == 0) return 0;

// Initialize result
int res = INT_MAX;

// Try every coin that has smaller value than V
for (int i=0; i<m; i++)
{
if (coins[i] <= V)
{
int sub_res = minCoins(coins, m, V-coins[i]);

// Check for INT_MAX to avoid overflow and see if
// result can minimized
if (sub_res != INT_MAX && sub_res + 1 < res)
res = sub_res + 1;
}
}
return res;
}

// Driver program to test above function
int main()
{
int coins[] = {9, 6, 5, 1};
int m = sizeof(coins)/sizeof(coins[0]);
int V = 11;
cout << "Minimum coins required is "
<< minCoins(coins, m, V);
return 0;
}

o/p:

Minimum coins required is 2