Hello everyone.
Welcome to the session.
So today we will solve my problem with the help of the occasion.
So the name of the problem is dramatic some ok do some genetic some.
Now what is the problem so the problem is very simple.
So given the value let's say the value of Case Three.
So what we have to do we have to calculate the cities we have to convert the sum of our cities.
Now the cities is very simple.
So this will be the cities to the power too.
And this is true to the poverty because the value of K Street.
So I will go.
So I will reach here.
OK.
One upon two to the power three basically in chart for a general key for a general cadence it is will
look something like this when I bought two plus two square two cube and so on.
One when two to the power game minus one.
Then one upon two to the power key.
Okay so we have to calculate the sum of the cities for a general key.
Okay.
The value of game will be given by the user.
And this is how the cities will look like.
So we have to use recursion to solve this problem.
Okay so how we can use recursion to solve this problem.
So what we will do we will break the series into okay.
So this is basically true to the power about zero.
Okay now we have a bigger problem.
So with the help of the guys in what we will do we will give the smaller problem to that equation.
So I will big the cities from here so if this total cities if I call it G some K so if I'm calling this
total cities as geometric some K so what will the cities be called.
So what is this series.
So this series is nothing but this is geometric sum game minus 1.
Okay so the equation will give me the answer for the cities okay.
Recursion I believe recursion I believe the function equation will give me the answer for the cities.
And after getting done I said what we will do I have to calculate this part.
So this part is not a thing but it is just one divided by two.
The power key so we can use the power function here.
Power of the power key.
Okay.
And that is how we will get our answer.
Okay so let us write the code now first of all before writing the code word we would answer for this
when the value of case 3.
So what do we answer.
This will be one plus.
So one by two.
This is zero point five when by four.
This will be zero point to five and then one by eight.
So basically this will be zero point 1 2 5.
So if we will add these four times we will get one point eight seven five.
So basically our return type will be a double.
Okay.
This will be a double fluid.
It will not be an integer.
Okay now let us write the code and we will check.
We will run our code against the value of equals 3.
Okay so let's write the code
so the return table will not be in digits sorry the return type will be double so I don't double double
and let's say that maybe the function is geometric sum so GSM what it will take it will take a number
as argument.
Okay.
So first of all base case we have to think about the base case.
So if the value of k is 0 so what is the answer.
If the value of k 0
Okay so let's see again so if the value of k 0 is the value of case zero what is the cities.
So the cities will be simply this one okay.
For k equals zero I will say this will be one plus one divided by not one plus two to the power zero.
Okay so this will be our city's fault because it'll This is our cities okay.
For k was 3 so I will go till 3 when the value of k 0.
I will go only this much okay.
Only one time when the value of cake was you know I have only one item.
So this is nothing but one by one.
So this is one.
Okay so what.
This is our base case.
If the value of KS is 0 I would answer this one.
Okay.
This is our base case so the value of Casey doing what I have to do.
I have not done one.
Now what do we do.
Recursive case so the equation will give me the answer for the smaller problem.
Okay so I will are done.
I will store down in a double variable and so double small onset because the return type is double.
So geometric sum
I will give give minus 1 to domestic some will give me the dramatic sum of game minus one times and
now the calculation but so the calculation part is very easy.
What I have to do I have to calculate one thing.
So I will return small answer plus.
Now what we have to do we have to calculate this part okay.
This is our last digit.
So this is the last digit.
This is the last digit.
I have to calculate this last digit.
So what I will do I will write when divided by two to the power key but this will be wrong because this
is integer and this is in data and digit upon A.J. will be in Indonesia.
But I want double value.
Okay.
So what I will do I will write one point zero.
Okay so that I can get done so as double.
So I will write to one point zero.
So double up on it T.J. will be the one only.
And then I am using powered function.
So power function takes two things as argument.
So I have to conclude it to the power key we can see here.
I have to calculate to the power key okay.
So this will be our code where the simple code.
And now let us this double code let us call the G some function and later the value of Case 3 and 4
3 we know the so should be one point eight seven five.
Okay let's run our file so our answer is one point eighty seven five solver code is working fine.
And if you want we can also do it.
We can also died in our court.
We can draw the diagram.
So the value of case T okay so case not too close to zero.
I will calculate.
I will call the function for 2.
Then I will call the function for 1.
Then I will call the function for 0.
So if the value of k 0 I am returning 1 so it will return 1.
So basically the small answer contains 1 and then what I am doing I am calculating I am returning small
answers I am returning small answer which is one plus one divided by 2 to the power key case one only.
Okay so what I am returning so this is basically one plus this is zero point five.
So basically one point five.
So this answer for that sort so the smaller answer is one point five and then I am again small answer
plus this part.
So basically what I am returning I am returning when playing five plus one divided by two squared because
the value of Case 2 so 1 divided by 4 when my 4.
So what is 1 before.
So when therefore is zero point to five.
So one point five plus zero point two five so one point five plus point two five.
So this will be five seven one point seven five.
So the small answer is one point seven five.
And then again the value of Case Three.
So a small answer plus one by eight.
And this will be one point eight seven five okay.
So when by it is zero point twenty five.
So if I will add one point seven five and zero point one two five.
So this is five seven eight and one point eight seven five.
So this is how that's how we will get our answer it will be one point eighty seven five.
Okay.
So I hope you understood this problem also.
Okay so that 10 day will be double.
And first we will write the code then we will think of the diagram.
Okay then we will write and I will call it first.
Write the code and then first write the code with the help of PMI and then draw the diagram.
Okay.
So I hope you understood this problem also.
If you're having it out you can definitely ask me.
Okay thank you.