 Welcome back. In the previous segment, we discussed the specification and the construction of the test cases. Next, we are going to look at how the problem is solved manually and what can be derived from it. How do you sum this series manually? Let me remind you what the series was very quickly. This was the series 1 over 0 factorial plus 1 over 1 factorial plus 1 over 2 factorial all the way till 1 over n factorial. So, you might say look this is fairly straightforward. In step 0, you may calculate the 0 term or 1 over 0 factorial and that is just 1. In step 1, you calculate the first term 1 over 1 factorial which is also 1 and you add that to the preceding sum that you had. So, the sum until this point was 1, so you add this new one to that sum. Then you calculate the second term that is 1 over 2 factorial and you add that to the sum so far and so on. You calculate the third term 1 over 3 factorial again add it and you do this until n. Now, here is an interesting question. Will you calculate each term independently? If you actually try to do it, you will very quickly realize that you do not need to. Very likely you will calculate the third term by dividing the second term by 3. So, the third term is 1 over 3 factorial. The second term is 1 over 2 factorial. So, that just needs to be divided by 3 in order to get 1 over 3 factorial and this is a general pattern. So, in step i, we need to calculate 1 over i factorial and that is simply 1 over i minus 1 factorial divided by i. So, in step i, you will take the term which was calculated in step i minus 1, divide that by i and add it to the sum which you are keeping track of. Now, notice that this general pattern is applicable to steps 1 through n not to step 0 because in step 0, there was no previous sum nor was there a previous term. So, this means for example that you might think of having a loop to do the work of steps 1 through n and step 0 might be something that you do before that. So, we have a reasonable understanding of what the manual computation is. Now, we are going to move towards a program. So, as we said the general pattern for step i is calculate the ith term by dividing the i minus 1th term by i and then adding it to sum. Now, we also said that this pattern is applicable to steps 1 through n and not to step 0. Alright, so this suggests an overall program structure which is we perform step 0 separately and steps 1 through n put in a repeat loop. So, that is good. We have made progress towards the structure of the program and now the question is what variable should we be using? So, here you should ask a very standard question which is what do we need to have with us at the beginning of each iteration or in particular iteration i. So, these are the things you need. So, you need the sum calculated in the previous iteration. You also need the term calculated in the previous iteration. Why? Because we said that we will take that term and divide it by i. This is the number of the iteration and then get what we want to add during this iteration. And of course, we need to know the value of i since we divide by i. So, these are the things we need to have and we need to have them from the previous iteration. So, which means we need to remember them. We need some mechanism to remember them. So, we are going to have 3 variables respectively to remember the sum, term and i and we are going to call these variables capital S, capital T and capital I. So, now we are going to develop the program. So, what we have said so far allows us to write this skeleton. So, we have the main program. First, we are going to read the input. Of course, we are going to define the variable n. Then we are going to define the variables we said we need i, t and s. And then we also said that we need the repeat loop. And so, we are going to have a repeat with count of n. And then finally, we are going to have to print out the sum which we are hoping will be in the variable s. And we also said that for the iteration, for the ith iteration, we would like capital I to have the value little i. We would like capital T to be the value of the term added in the i minus 1 iteration or in other words 1 over i minus 1 factorial. And we also want s to be the sum calculated in the first i minus 1 iterations or the value 1 over 0 factorial plus 1 over 1 factorial all the way till 1 over i minus 1 factorial. So, this is our skeleton. And now we are going to build it up. So, what we really need to do is to make sure that the plan that we have written down can be realized. So, let us talk about the first iteration itself. Can we make sure that the values of i, t and s are as we have asked for. So, for example, in the first iteration that is little i equal to 1, we want capital I also to be little i or we want capital I to be 1. Likewise, we want T to be 1 over i minus 1 factorial or 1 over 1 minus 1 factorial or 1 over 0 factorial or 1 again. And s must be the zero term of this series. So, it is also desirable to have s equal 1. Well, the only way we can make sure that this happens at the beginning of the loop of the very first iteration is if we initialize the variables to these values. So, that is what we are going to do. So, we are going to write an assignment statement i equal to 1, t equal to 1, s equal to 1 or separate statements and this implements our plan for iteration 1. How do you implement it for the subsequent iterations? Well, one thing we have said was that in the i-th iteration, we need to divide the previous term by i and we have the value of the previous term. We are expecting to find it in the variable capital T. So, we should be dividing T by capital I. Now, the question is where should we put it? So, we are going to put it in T itself and here is the reason for it. The value that T originally had was 1 upon i minus 1 factorial and this value we are not going to need. We are going to need the value that we just calculated T upon i, which is 1 upon i factorial and since T is going to be the variable which in the next iteration is anyway expected to hold 1 over i factorial, we might as well store that value in T itself. Next, we said that we are going to add the newly calculated term to the sum and in fact, the right statement to use for that is just to say s equal to s plus t. So, note that this now means that s is equal to 1 over 0 factorial plus 1 over 1 factorial, all the way till 1 over i factorial. And finally, to prepare for the next step, we really should be changing capital I to i plus 1. So, that is what we are doing over here. So, with these three assignments, you can see that i, t, s now have the correct values for the next iteration. So, our work in this iteration is done, but not only that, t, s and i, we have changed so that they have the correct value for the next iteration. Why is that? Well, as you can see, capital T has the value 1 over i factorial now. In the next iteration, which is i plus 1 iteration, it really should have this value. Then sum in the i plus 1 iteration should be the sum of all the terms from 1 over 0 factorial to 1 over i plus 1 minus 1 factorial or 1 over i factorial. And that is exactly what we have here as we have written down in that comment. And finally, capital I should take the value i plus 1 at the beginning of the i plus 1 iteration. And that exactly is what we have done. So, we have followed our plan, not only that, we have done exactly what we used to do in the manual computation. And therefore, we have finished writing the program. Now, in this program, we put down some comments about what plan we are going to follow. So, these are the black lines over here. So, these two lines, these two lines tell the user whatever plan is. This is absolutely necessary. If somebody else is reading your program, they should know this and if they know this, it will be much easier for them to follow what is going on. Now, one more important point, the order in which we updated ts and i is very important. So, for example, you cannot update i first, that would not really work. You cannot exchange the order of these statements. So, since in these statements, each variable is going to have an old value and new value, you had better be very careful as to taking into account what value it is that we want to add to which variable or multiply each variable or whatever that case might be. And then make sure that the update to that variable happens at the right time. In other words, statements like these will have to be handled carefully and the order of the statement is going to be really important. So, the considerations will be do we want to divide t by the old value of i or the new value and depending upon that the ordering should be done, the ordering of the statements should be done. Similarly, you want to say do you want to ask, do you want to add the new t to s or old t. So, after this, we are going to execute the program. So, for this, of course, we should type the program into a file or into the IDE. Compile it and then run. And we should use the test cases constructed earlier. So, let us see this. So, here is the program that we just wrote. So, let us compile it and let us run it and let us try our 4 test cases. So, the first was 0 and we were expecting the value 1. So, we got the value 1. Let us try one more case. So, when we type 1, we expect the value 2, yes. And when we try 2, we expect the value 2.5. Let us see if we get that, yes. And finally, let us try some large value, say maybe 10. And we get 2.71828, which is in fact, exactly the value to 5 decimal places. So, our program seems to be doing just fine. So, here is what we discussed. So, we said that translating manual algorithms into computer programs is important and what you are supposed to do during that is figure out the structure of the manual algorithm. And this will tell you how many iterations are needed for the repeat loop that you might use in your computer program. Then you are supposed to identify what you need to remember at different points of time in the manual algorithm. And this will tell you what you should be storing in what variables. And this, thinking about the manual algorithm and figuring out its structure and so on is probably the most important activity that you will learn in the course. So, please get it right. So, we will stop over here and in the next segment, we will see what to do if you make a mistake.