 Today I propose to begin the analysis of mid-sep paper. I find in general that the performance has been okay, although some people still have problems in dealing with control structures and arrays. The first question was relatively a simple question. There were a series of conditions that were to be checked and you had to execute statements based on the condition. I have here a program segment which implements that control structure. This was actually straightforward. Such questions would not be there in my exams normally, but since I noticed that some students had problems in the basic control structures, I thought I'll give them a chance to demonstrate that they understand these. Fortunately, most of the people have answered the first two questions correctly more or less, although there are still some people and I would advise them to attend the extra lecture which I'll announce shortly to clarify these things. Certain simple things people still make mistakes on. Inside the if statement, whenever you are checking for equality, you have to use equal equal because that is the comparison symbol for equality, not just one equal. One equal to sign is used for assignment like this. So please keep this in mind. Similarly, it's a good idea to indent your if statements such that it is understood which if statement closes where, which else statement closes where and which if statement has the corresponding else. Ordinarily, I would have written this also in this fashion, but because it is on the slide, it is written like this. In the actual programs, which I will put up on the website, you will have these properly indented. The part B was another simple part where you had to decipher that you could use the for iteration. And that is because in the block diagram, what was stated was not just some equal to zero, but also I equal to zero. Some people have written I equal to zero here and still have this for iteration. It is not incorrect because that initialization of I equal to zero is superseded by the initialization that the for loop does. However, it is important to recognize that when I use the for instruction for setting up of a iteration, it does three things. The initialization before the loop, the increment after every iteration and the check for the final condition. Since all these three things are embodied inside a single specification, there is no need to initialize I equal to zero above this, although that is what was given in the flow chart. You were to convert the flow chart into an appropriate control structure, so this would have been the more accurate representation. You would notice that in the question one B, in the flow chart, there was a conditional iteration based on some value some greater than 32. What this particular program segment does is very artificial. However, the idea was to test whether you can recognize that that particular block could be implemented using a wild statement and that the wild should be nested inside the for iteration. So you have an outer for iteration. Within the for iteration, you have a wild iteration. Notice that some is reduced by three every time and this iteration will continue till some becomes less than or equal to 32. When some becomes less than or equal to 32, you will quit this and come out. And of course, when you come out of the wild, you will still go for the next time and you'll continue the iteration. These were simple questions intended to test whether you can quickly and correctly implement iterations because iteration and the conditioners are very fundamental control structures. Frankly, using these, you can implement any logic that you want, although there are some simplifications as we shall see in later lectures and even today. The second question again was simply to test whether you can convert a problem statement into an appropriate logic, which was pretty simple. You had to evaluate a new salary or a modified or enhanced salary given a particular salary value and the enhancement rules were stated as you have to increment the salary by 22% if the salary is less than 10000 and if the salary is between 10000 and 20000, you have to increment it by 23%. There is an additional condition that if the enhanced salary goes beyond 30000, it has to be restricted to 30000. However, if you analyze the problem statement, you will find that the question of 30000, etc., will never arise. Further, the question did not stipulate what exactly you should do when the salary is exactly 10000 rupees. For less than 10000, it specified an increment. For salary between 10000 and 20000, it specified another increment. But at 10000, exactly it did not specify it. Here is one solution where I check the salary. Note that I have to return a value. I could ordinarily return a value the moment I have computed it, but I may not know the computed value till the very end because my logic might have nested ifs and whatever. So, in general, it is a good idea that if you want to return a value from a function, you calculate that value in a variable of your own and that is why I have declared float new cell here. Notice that all of this is part of the function. I have not written the top statement function so and so. That statement, in fact, was given in the problem itself. So, here I check if the salary is less than 10000, I increment the salary by 22%. Not 22% can be most simply computed by multiplying the existing value by 1.22. Else if, that is, salary is not less than 10000, but it is less than 20000. Clearly, it is between 10000 and 20000, in which case new salary is computed as 1.23 into salary. Else, new salary is simply salary. There is no increment. So, that is the logic that is stated in the problem. However, to cater to the two special cases which I just mentioned, it might be worthwhile to put a comment in your program which says case of salary beyond 30,000 does not arise, which is a statement of fact. Similarly, salary of rupees 10000 included for 23% raise. You could have included this in this block itself by saying salary less than equal to 10000 is the value. And you would have been right because nothing has been stated. You have to make some assumptions. The idea in any software development is that specifications will always, always be incomplete. You are all used to solving problems in your exams where specifications are exact. Programming problems in real world are never like that. Requirements, functionalities that are desired by your program are generally very vaguely stated. In fact, as we shall see later in the course, when you start doing your projects, one of the early tasks that a programmer must do is to define those specifications from what one has heard or what one has read. And then get them weighted again. That is known as a software requirement specification document or SRS. Software requirement specification is a huge thing. And lots of people spend lots of time in just clarifying what is wanted. So even in such simple situations, when you are not clear on what is wanted, you must state those assumptions. And that is why these commands, which have nothing to do with the program, but they are relevant for any reader of the program who understands that the specifications were inadequate or inaccurate. And therefore you have stated what you have assumed. I suppose these two problems were very clear and simple. Addition and subtraction seems to be such a trivial matter. All of us learn it in the early days of our schooling. It is useful to remember that adding and subtracting very large numbers could be non-trivially complex. As a matter of fact, if we do not have a positional decimal system as we do now, the subtraction particularly and even addition could be extremely difficult. Let me give you an example. Are you familiar with Roman numerals? This stands for what? One. So you write two and so on. This is what? Five. This is ten. This is? This is? Yes? Okay. So I now write a number. How much is this number? 101. And I want to add to it, how will you perform this addition? How will you perform this subtraction? Any idea? Till the time that the positional number system reached Europe via Arabia, Europeans could not do arithmetic easily, even the educated Europeans. A positional system, whether the base is decimal as we use it now or the base is binary or hexadecimal or octal or whatever, requires the existence of zero. Without zero, you cannot have a positional system. A positional system such as means actually this is 400 plus 18 plus 3. You agree with this? This is the interpretation of a positional system. Each digit represents an integer power of ten, ten to the power zero, ten to the power one, ten to the power two, et cetera. And without this zero, you cannot actually interpret a digit position. And the existence of a zero permits you to use the notion of a carry or the notion of a borrow in any addition or subtraction that you do. Consequently, if you now look at these numbers, the numbers which are shown here, the input is given, first the number of digits is given and then this is followed by the actual individual digits. The another number which is a six digit number and the six digits follow this. Many of you have made a mistake of simply reading the number in some variable and then try to put different digits of that number into an array. Note that you just cannot do that. Any large number cannot be read in the normal variable of C plus plus because the normal variable of C plus plus has a limitation of so many number of digits. Whether you use int or whether you use long, it will have only so many digits and not more. So if you want to read a 70 digit number, there is no way a single entry of 70 digit number will get you anywhere. It's not possible. Impossible. We shall see later on the meaning of this limited capacity. In fact, it is this limited capacity that we deal with which permits us to say that addition and subtraction will take a fixed amount of time because two numbers are added by electronic circuitry. Whether the number is one digit or three digits or five digits, addition of two numbers takes the same time. But that is up to seven digits or 10 digits depending upon your procedure. Beyond that, there is no representation possible. If you want to really add or subtract large numbers, which is what you might be required to do in many mathematical operations, there is no way but to seek alternative representation. What was given was one such alternative representation and you are supposed to implement addition and subtraction. The original representation that I had thought of for the paper was this. A representation where you might have a long array, but the digits are aligned to the right. You will agree that such a representation will make it much easier to add or subtract numbers. As a matter of fact, logically at least, you will have to align these numbers like this. If not actually, then in terms of the index manipulation that you do because there is no other way of adding or subtracting numbers using positional system. So when you want to add these two numbers, what you will do, this is the way you will add these numbers. In the unit position, you will add the unit position. In the tenth position, you will add the tenth position and so on. Notice that this 7 plus 1 is 8, 5 plus 2 is 7, 5 plus 3 is 8, but 9 plus 6 is 15. So whenever you get a number which is more than 9, you are supposed to retain the last digit and carry one forward here. That carry 1 is added to 9, yielding 10, you retain 0 here, carry one forward. This 9 becomes 9 plus 1, 10. Again you put 0 and carry one forward. Since there is nothing else to add, you put that last carried one as an extra digit. This appears very simple. Let me further elaborate this process for the purpose of constructing an algorithm. We now understand how addition is done. So I have written these numbers back here and I have left some space here which I will say is the space for carry. Notice that I am going to store these digits into two arrays. So it is the array elements that I have to deal with. In general, whenever I am dealing with an i-th element, I will have to write it in terms of the i-th element of this array and i-th element of this array and the carry meant for that position. So it is better that I generalize my calculation mechanism so that I can set up an iteration. I can't do that digit by digit obviously because I don't know the total number of digits or priori. That number is stored in the first element of an array. Notice that this number is a four digit number. This number is a six digit number. My addition therefore will have to be carried up to six digits actually and there could be a seventh digit if there is an overflow. Consequently, the result array that I declare should preferably have an extra digit position in order to store that extra. Although that is not essential, you could always take the view that if there is an overflow, I am sorry I cannot represent that number and the overflow goes out as long as you detect that overflow and state that error. So consider two arrays that I am using something like m- this I call n- and the result array I call r- but I declare it to be of 101 elements. So I will have all zeros on this side. The number of digits in each number is given by the 0th element of m and n. However, in all way to align my algorithm correctly, since I know that I have to carry on this addition exercise, till the digits of the larger number are exhausted, I should calculate some variable called maximum digits or total digits or something and I should assign the value of the larger of the two. This has four digits, this has six digits, so the max digits should have a value of six. That much is obvious. In general, I will be adding not two values but three values. I will be adding the digit of m dash, digit of n dash and a carry. The point is I will know the carry for subsequent positions depending upon the result of the previous addition. But I do not know the carry for the very first position. Well, I actually know there is no carry because there is no addition performed. Now since I want to generalize and I always want to write this addition, so ith element of r dash, I generally want to say m dash i plus n dash i plus carry. This is the generalize statement I would like to make. Now obviously, to begin with, there is no value for carry. Carry will come out through my addition process, so I can initialize carry to zero artificially at the beginning and therefore I can have a generalized. Since I have stated that I want my array r dash to be one digit longer than m dash and n dash, I should not be putting this into the ith element if I am adding this here because the last digit of r dash 101 will be in r dash 100 and not r dash 99. So I might as well, when I want not ith element but i plus one ith element. Of course, if you are using an array which is 100 elements, r i will be perfectly fine. This is the logic which I want to implement and this is the way you must think about solving such iterative problems that I have to add digits, I have to add a carry except for the first digit there will be carry everywhere which will be either zero or one. Zero is a natural thing, it does not affect any addition and therefore I shall assume a zero carry to begin with. If I do that, then I can set up an iteration which will move from the last digit of the number to as many digits as are required to cover maximum digits and that is the end of my addition. Using this logic then this is the program segment which will add the two numbers. Here I have introduced the new statements max digits equal to m zero greater than n zero question mark, m zero colon n zero. This construction you have not seen earlier, so let me quickly explain this is a specialized version of an if statement where the if statement ends up in a single value. So depending upon the condition that you test that value could be either this or that. If such is the situation then ordinarily I would be writing this statement in the following fashion. I want to compare m zero and n zero. Notice that as per the specification the zeroth element which is the first element of the respective array contains the total number of digits. So in our case m zero will contain four and n zero will contain six which are the number of digits in these two example numbers. Now depending upon which one of them is larger that shall be the number of maximum digits that I have in the two numbers. So I am just comparing whether m zero is larger than n zero. If it is then max digits are m zero. If it is not then max digits are n zero. What happens when both numbers are equal? It does not matter whether you assign m zero or n zero to max digits because both are same. Effectively at the end of this small block you will have the maximum number of digits that exist in either of the two numbers. Now this logic may be required very often in your larger computational programs. You just want to set a value either this or this depending upon which one is larger or which one is smaller. Or if numbers are equal you want to give the one value otherwise you want to give some other value. To simplify the representation of this logic C plus plus permits you to write a different format altogether. It permits you to check this condition by writing that there is no if statement required. You want to calculate the value of max digits. So what you will do is you will simply write an assignment statement. You want to assign this value. You want to assign either m zero or n zero. Depending upon whether a condition is satisfied or not satisfied. So all that you are required to do is to write the condition here. In C plus plus this is actually a valid expression. It is called a comparison expression. As we know a comparison results in true or false. C plus plus beautifully uses zero and one values to represent true or false. So it has a numerical value also if you want to assign. However that is not the purpose here. The purpose here is to say please evaluate this condition and to indicate that this condition has to be evaluated you put a question mark. So this is called a question mark operator. While this could be a legal statement although giving meaningless value this is alone is not a legal statement. This is only part of a statement. This part says check question mark. Is m zero greater than n zero? Question mark. If the answer is yes whatever you write here will become the value of the whole expression. If it is no then whatever you write here will become the answer to the final. So you write here m zero and on this side you write n zero. It is not necessary to write only single variables or array elements. You can write expressions. The key initiator here is the colon. Between the question mark and colon whatever expression you write is evaluated and assigned it becomes the value of the expression to be assigned to the left hand. If this condition is false then whatever you write after colon but before the semicolon that expression is evaluated and that value becomes the value to be assigned. So in short this is nothing but an extremely simple way of writing in an abbreviated fashion exactly what we want to write here. This is well accepted as a standard notation for many things where you want to do such simple side. So is this clear? The question mark operator as it is known. Fine. Let's go back to the original problem. So if you look at the algorithm now if m zero is greater than n zero I would have assigned max digit as m zero otherwise max digit as n zero. Remember what I said I will assume carry to be zero. Now I have to run an iteration going backwards from the last digit. The last digit is 99th digit because the size of the array is defined to be hundred. From 99 how much backward do I go? I know there are maximum max digits. What would happen in case I have this smaller number which is n dash in this case and which has only four digits. I have assumed that the four digits will be stored in the last four positions. But can I assume that there are zeros in the previous positions? After all this is not the original array that I will get when I read it. So when I transform the original array into m dash and n dash I must ensure that all these elements are set to zero first and then I push the actual digits of the two numbers into the last positions. We shall see that in the subtraction example. But this is just to tell you how addition is done if the numbers are stored like this. How? That there are two arrays m dash and n dash and they contain the digits in the right justified fashion. The first digit still contains the number of digits actually but right justified fashion and the rest of the digits are assumed to be zero. That is the assumption in this algorithm. So I now start doing this and set up a backward iteration starting from 99 and going all the way up to 99 minus max digits plus one. Whether to put plus one or not to put plus one is something that you should check manually by checking what is the last digit that you are entertaining for the addition inside this loop. This is the correct representation by the way. Now what I do in every iteration? In every iteration I simply add the i-th element of m dash and the i-th element of m dash with the carry. Initially carry is zero so it does not matter and the result I am not putting in r dash i but I am putting in r dash i plus one because as I said I am assuming that I should provide for an overflow which might occur if two large numbers are added and therefore the result r dash array has an overflow. Now I have to check whatever I have calculated if this addition results in a number greater than line what does it mean? I have got a carry because the total added up to 15, 17, 18, 11, 10 even. 10 is a two digit number. So anytime I have a two digit number that is greater than 9 I cannot retain that number as a digit and I have to take a carry out. So all that I do is I set the number modulo 10 to be that digit. Obviously 10 modulo 10 is 0, 15 modulo 10 is 5, 19 modulo 10 is 9, 22 modulo 10 is also 2. However I know that I will never get 20 because I am adding two individual digits each one of which is less than 10. So even if I take a carry and I have two digits as 9 and 9 I will have 9 plus 9, 18 plus 1 carry 19 I will never get 20 or beyond. So I have no problems on that. As a result I put this modulo result in r dash i plus one and set carry to 1. On the other hand if I have a single digit then there is no carry equal to 0. Why is it necessary to set carry equal to 0 here? After all I did set carry equal to 0 here. Any suggestion? After all I did start with carry equal to 0. So why inside the iteration I am again setting carry to 0? The simple reason is that I might have a carry equal to 1 let's say in third position. But in subsequent positions even after absorbing that carry I get a single digit number and there should not be any carry further. If the carry gets set to 1 at any position it must not remain set to 1. The value of the carry will depend upon every individual addition and it is not a generic value. So remember that if I get a two digit number at any point the carry is 1. If I get a single digit number at any point the carry is 0 and I have to set it so explicitly. It is incidental that I am setting carry equal to 0 to begin with and this is done only to generalize this formulation so that I can have a single statement which can be iterated upon. I don't have to handle the case of first digit separately. That is the purpose. Is this logic clear? Some people have commented I got some several mails by the way on this some mails were very good. One particular question was that this question took a long time 3a and 3b and that 3 marks were not justified for that. Is that a unanimous opinion? Yes. Let me take a break for half a minute and explain the philosophy but you are right by the way the original question which I had said had the m and n represented in this fashion so what I have m dash and n dash is the representation. But I figured out that that problem could be solved very quickly and therefore I wanted to test the logical abilities of people to think on their feet and get either addition and subtraction done like this in spite of the representation being weird or converting that weird representation into this kind of representation carrying out the addition and subtraction and putting back the representation in the original format. I thought that will take some time. It did and it did confuse a lot of people. I am sorry for the confusion but these things happen as regards marks well the word including exams are never fair particularly my exams you will find this repeatedly. There will be some simple questions at the beginning which will try to test the basic understanding of everyone for those who have done a lot of practice and have talent to work out extremely complicated logic very well they might find those questions very simple do not forget that there are people who find even that to be difficult because they never had any background so it's okay you can solve those problems in two minutes there will be some problems which may take much longer such as these problems the acquisition of marks on the higher end is highly non-linear and skewed in my exams you can move very fast from zero to something then for every mark you will have to struggle and in the final exam you will invariably have at least one part of a question which nobody can solve at least I said a question like that and I am delighted I have not taught this course for 20 years but I used to be delighted that every exam there will be one or two jokers who will come up with brilliant solutions for that and then I would announce their names to the class so this is the program segment to add numbers subtraction is harder you all agree subtraction is harder how many people got question 3C correctly 1, 2, 3 no either two people are missing or they are not confident of their solution because I got 5 correct solutions of course they were syntax errors but people got the logic correctly let's understand the subtraction it's a very interesting thing I have given here an example of two numbers the first number is 1, 7, 0, 0, 5, 8, 2 the second number is 6, 7, 4, 9 I want to subtract the second number from the first number however I don't subtract numbers like this just like in addition I subtract numbers using a traditional system so therefore I would like to right align these numbers and after right alignment I would get the numbers as here 1, 7, 0, 0, 5, 8, 2 and then implicitly 0, 0, 0 here and 6, 7, 4, 9 this is how I will subtract you all agree this is how I will subtract so I deal with this representation so how do I do the subtraction here I do the subtraction the Indian typical style of subtraction that we study in the elementary school I put one more thing here for a borrow and a carry can I subtract 9 from 2 answer is no so I borrow 1 from here this becomes 10 this number becomes 12 12 minus 9 is 3 but since I have borrowed 1 I have to subtract that 1 from this this thing further so I put a minus 1 here just to indicate that not only I have to subtract 4 from 8 but I have to further subtract 1 which I had borrowed when I subtract 4 from 8 I get 4, I subtract this one again I will get 3 there has been no borrow here so I put this number as 0 I don't have to do any further subtraction again I find 5 is larger than 7 so I borrow 1 from here this becomes 15 15 minus 7 is 8 but I have borrowed so I have to subtract 1 from here I can't subtract 6 from 0 I have to borrow 1 from here this becomes 10 10 minus 6 is 4 4 minus 1 is 3 but I had borrowed 1 there is nothing here but there is a 0 implicit 0 I can subtract 0 from 0 but I cannot subtract 1 from 0 so I have to borrow 1 again I get 10 10 minus 1 is 9 I have borrowed so I have to put 1 here I can subtract this one from 7 so I get 6 there is no borrow here I subtract 0 from 1 and I will get 1 I cannot complete the subtraction that I do just to understand the signs correctly I might want to do the following I might want to propagate the negative sign to the second number which is to be subtracted from the first by the way I'm assuming that both numbers are positive and the first number is larger that is the assumption under which this program shall be seen however we can generalize it easy but I'm just trying to go through So what am I saying to say? I have to subtract 6, 7, 4, 9 from this. I will propagate negative sign to every digit position. So this will be 0, minus 0, minus 0, minus 6, minus 7, minus 4, minus 9. There is nothing like minus 0. All that I am saying is whatever is the digit I have put there, I will make it negative. I am assuming all digits are positive otherwise. Now this makes sense to me for subtraction because I convert every subtraction into addition now. I don't have to subtract. I will just add this with minus 9. I will just add 8 to minus 4 and 2 minus 1 if necessary and so on. This is a generalized mechanism that I can use. There is only one problem. In the case of carry, I knew when I had to carry a digit here depending upon whether the result was a 2 digit number or a 1 digit number. In this particular case, whether I have to subtract this minus 1 from the next digit or not depends upon what I have borrowed. My logic then becomes complicated that if I have borrowed, then I have to subtract minus 1. If I have not borrowed, I don't have to do anything. One of my TAs actually found out a generalization of this by saying why not I always borrow, whether it is needed or not. Now that makes a very interesting logic which I write here. Notice that I have decided that I will always borrow and if I always borrow, I always have to subtract something from the left hand side. Now I borrow here, this becomes 12. I subtract 9 from it, I get 3. I get actually 0, 3. I can get a 2 digit number now since I am borrowing unnecessarily. I treat this 2 digit number as a given and extract 2 separate digits from it. I retain in my result the value 3 and examine the more significant digit. If it is 0, then I indeed needed a borrow. So therefore I will put a minus 1 here because this was 0. Since I am borrowing again from here, this will become 18. I am blindly borrowing but I am not changing these numbers. I am simply adding 10 to each number as if I am borrowing everywhere. So this number will become 18. When I subtract from 18, 4, I will get 14. I subtract one more, I will get 13. I write here 13. Obviously 13 is not the correct answer. So I have got 2 digit number here with non-zero significant digit. Again I break it into 2. I retain 3 as the result and since I have got this digit as 1, it tells me that the borrow was unnecessary. I did not have borrow. I could have subtracted easily and therefore I will not subtract anything from here. So my carry this time is only minus 0. I will subtract 5, not 7 from 5 but 7 from 15 as I mentioned. 7 from 15 when I subtract I get 8. I subtract 0 from here. I get 0 8 here. 8 is the answer, digit for here. The second digit is 0. That means I needed a borrow. So I put minus 1 here. So whenever I have a 0 digit, it gets into a carry of minus 1. Whenever I have a digit 1, it gets into a carry of 0. This simple logic then becomes a uniform logic because for any individual position being smaller or larger, it does not matter. And I know that I can always borrow because I know the top number is larger than the bottom number. So under these assumptions, this logic will work. The logic is, actually there is an Austrian method of subtraction. The standard European method is slightly different where depending upon borrow, you subtract one from the top digit itself and so on. Indians do it like this. You subtract one more, you don't change the top digits. That's the Austrian method also. Those of you who are interested can look up either the Wiki or just search for Austrian subtraction. Not Australian, Austrian subtraction. You will get a logic. The Austrian subtraction logic and Indian logic are very similar. What my MTEGT has done is simply extended it and say don't waste time in examining whether you need a borrow or not. Just borrow. Keep borrowing from every digit and then you only need to work out the correct carry logic. If you have a single digit number, that means you needed a borrow so you subtract one. Here, here, maybe here. If you did not need that, you will get a two digit number. That means you will get a number in 2019. Notice that whatever you are borrowing only 10, you can never get the result to be more than 20 or equal to 20. Again, you can prove that. Using this logic, you can implement a generalized loop structure exactly like we did for addition and you can get a subtraction here. So, let me quickly go through this program statements here. First, there is a whole lot of commands saying what exactly you wish to do. Two high pressure numbers to be added, how the numbers are represented, etc. Since this is a program written for subtraction, it says specifically that the second number N, which is negative, is stored similarly except N0 showing number of digits is a negative number. All other digits are positive. Remember that is the specification that was given in question 3c. That the individual digits of the number are positive, but that the number is if there is a negative number, it will be represented by minus sign for the number of digits. Assuming that and assuming that M is larger than N, the following algorithm works. So, here are the two arrays M and N. As I mentioned, R is declared to have one extra digit. I read the two numbers in arrays M and N. I use an input flag, which is a generic flag which will be zero ordinarily if I keep getting the correct numbers and digits. But if there is some anky-panky, input flag will be set to non-zero and I will just exit from the program. So, I call it input flag used to check input health. I read M0 and I check whether M0 is less than zero or M0 is greater than 99. This statement is justified in the fact that I am assuming that the first number is positive and is the larger of the two. So, obviously M0 must contain a positive number. If it is not, I set input flag as one and get out. Otherwise, I read from one to M0 individual digits of the first number and store them in the array MI starting from one to the number of digit position. If any individual digit is greater than nine or is less than zero, I must cry out. Please notice, you cannot make an assumption that the input given will be a single digit. Somebody might by mistake type 25. 25 is not a digit, it is a number. Since you are reading a number, M1, M2, M3, they are all numbers actually. It is your mind which says each one of those elements will contain a single digit. The computer has nothing to do with it. The computer will accept any number. It will ensure that what you give is a single digit and therefore this check is mandatory that the number that goes in is less than nine and greater than or equal to zero. Less than or equal to zero. If it is not so, again you announce bad digit at such and such position, whatever, whatever and get out. You read the second number similarly. However, we have said that the second number will be given as a negative number if I want to subtract it. Therefore I am reading N0 which is expected to be some negative number between 1 and 99. So correspondingly the check is that if N0 is greater than zero that means a positive number or if N0 is less than minus 99 that means too many digits are specified. I will neglect all of that. Then of course I read the individual digits and notice what I am doing. I am setting up N0 as minus N0 because it was a negative number I converted into a positive number because that is the number of digits. I cannot afford that to be a negative value. However, when I read individual digits in N somewhere I will have to transfer them to my representation and when I do that I will associate a negative sign with them. So this is just the reading of input. These are just checks. First for subtraction I do a shifted representation. I define arrays M dash, N dash and R dash and I define a carry, borrow and max digits as usual. I put zeros in M dash and N dash and also in R dash and I put R dash 100 as equal to zero which is the extra digit that I will get in R. Now I am propagating the given numbers into these arrays and I am propagating negative sign to each digit of N dash. So notice what I am doing for all the first number in M I transfer the digits of M to M dash. For the second number in N I transfer minus of that digit to N dash. So automatically N dash has minus digits M dash has plus digits all aligned to the right and I am ready to get my algorithm. Before that I do this for max digits as per the formula that we just studied and this is the complete logic of subtraction. I subtract the second number from first starting from last position backwards. I say carry equal to zero. I said borrow equal to 10. The borrow will never change because of the extended logic by my TA. Now I go from 99 to 99 minus max digits plus 1 as usual I add M dash plus borrow plus N dash. Notice that N dash is negative number. So I am actually subtracting. Notice that borrow to begin with is zero but it may become minus 1 later in case the borrow was truly required. I put I check R dash I plus 1 if it is greater than 9 I take a modulo 10 and I said carry to zero. Otherwise I said carry to minus 1. That's it. Why am I putting plus borrow plus carry here? I could have said plus 10 here directly. Because I am borrowing 10. The reason I am not doing it is I want you to examine the possibility of generalizing addition and subtraction by writing a single function. You will notice you can do that by appropriately setting the values of borrow and carry depending upon whether you are adding or subtracting and therefore it helps to put a variable here rather than a fixed number. In fact it helps to put variables wherever you are putting constants because for example if your array was to suddenly become 200 digit long this 99 will come in the way. We shall examine these issues when we continue this analysis on the Thursday lecture. We will stop now. Thank you.