Can anyone help me solve this question please? Elisa Kazan^1 loves to drink cide
ID: 3788367 • Letter: C
Question
Can anyone help me solve this question please?
Elisa Kazan^1 loves to drink cider. During the weekend. Elisa goes to the pub and runs the following recursive algorithm, which takes as input an integer n greater-thanorequalto 0: Algorithm ELISAGOESTOTHEPUB(n): if n = 0 then order Fib nachos else if n is even then ELISAGOESTOTHEPUB(n/2); drink n^2/2 pints of cider; ELISAGOESTOTHEPUB(n/2) else for i = 1 to 4 do ELISAGOESTOTHEPUB((n - 1)/2); drink (n - 1)/2 bottles of cider end for; drink 1 bottle of cider end if end if For n greater-thanorequalto 0, let C(n) be the number of bottles of cider that Elisa drinks when running algorithm ELISAGOESTOTHEPUB(n). Determine the value of C(n).Explanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
int ElisaGoesToThePub(int n)
{
static int pint=0;
if(n==0)
return 0;
else if(n%2 == 0)
{
pint += 2*ElisaGoesToThePub(n/2)+pow(n,2)/2;
}
else
{
for(int i=1;i<=4;i++)
{
pint += ElisaGoesToThePub((n-1)/2) + (n-1)/2;
}
pint+=1;
}
}
int main()
{
int n;
cout << "Enter the value of n: ";
cin >> n ;
cout << ElisaGoesToThePub(n) << " number of bottle cider Elisa drinks." <<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.