 Now we consider control flow in a program when we write instructions one after another they are executed in the sequence in which they are given. C++ permits us to combine all instructions written in one sequence and put them in a block. So everything put inside a block is considered equivalent of one instruction. For example, these are three instructions. Assume that they are all defined as integer. These three instructions are executed one after another. But suppose I want to combine them and treat them logically as if there was a single instruction then I can do that by writing an opening brass here and a closing curly bracket here. So whatever comes inside an opening curly bracket and closing curly bracket is logically considered as equivalent to one instruction. When program is executed all these instructions will be executed. In fact, C++ says it doesn't matter what kind of instructions you put inside opening curly bracket and last curly bracket. There may be if then else, there may be conditional, there may be iteration, whatever, whatever. All of that is treated as one block and equivalent of one instruction. Therefore, whenever C++ permits you to write one instruction and if you have to write more instead of one, you always put a block, start, end. So all that is equivalent of logically one instruction. Is that clear? This is how the sequential instruction is written. But sometimes I want to execute conditional just to recall the flow chart. Suppose I have a flow chart which says read X and Y. You understand this logic? I want to read two values X and Y. Compare which is greater and whichever is greater I want to assign it to Z. So after executing this Z should be the larger of the two. Now I can't write a sequential statement. So for that you have the if statement. In the if statement, you will write this as, is this clear to everybody? So what does the if statement do? It checks if X is greater than Y. Only if that condition is true, it will execute that statement. If that condition is not true, it will execute the statement written after else. The logic for this is, now this is very important to note that the if statement permits exactly one statement to be written after if and exactly one statement to be written after else. You can't write 20 statements that if X is greater than Y then do this, do this, do this, do this. Else do that, do that, do that, do that. There is no direct method of writing such a thing in C++. You can write if X is greater than Y, do this, else do that. That's all, this and that, one statement only. That is why the format of description of if statement in C++ books you will find says if condition, statement one, else statement. But suppose you have to do many things. If X is greater than Y, do this, do this, do this, do this, else do that, do that, do that, do that. Then how will you write? Curly bracket because of the C++ rule that whatever you write in a curly bracket pair is one statement. So you can write if you understood this. Sometimes if you miss curly bracket there is a problem. Sometimes we deliberately don't write curly bracket because we have only one statement to execute. So please remember if only one statement is to be executed then you write it without curly bracket. But otherwise you must always write it. And as a result I have been suggesting that a good programming practice is always to put curly bracket. Even if there is one statement there is no harm. Because later on if you suddenly remember oh if that condition is true apart from this I also have to do this and this. Then I can insert it and it will not be a mistake because I will be putting that inside the curly bracket. Is that clear? What if I write only one statement? Let's say what will this program do? It will read two values m and n. If m is greater than n then p is equal to m and output p. So suppose the values given are say 7 and 5. What will happen? What will be the output produced? p is equal to 7. So output will be 7. Suppose the value given is 2 and 9. Now what will happen? There is no question of no output. C++ is like a rakshas or a jinn. So if it is output then output. This is very very important to understand. Why you are saying no output first of all? Because you have not assigned any value to p. If m is 2 and n is 9 then you read m and n. If m greater than n is it true? No. So p is equal to m will not be executed because that condition is not true. The next instruction says output p. Please remember that when you write this program the compiler would have assigned locations 1 for m, 1 for n, 1 for p in some memory other thing. Now in this case when m is 7 and n is 5 p will get a value assigned which is 7. But if m is 2 n is 9 p will not get assigned any value. How do we represent such values? We write a question mark inside saying we don't know. It is very important to understand that we don't know. And when we don't know C++ also does not know. So suppose you are executing this program just now on an Ubuntu machine. There are memory locations, millions of memory locations. And when the program is compiled and loaded for execution m, n and p have been assigned some locations. Each one of those locations contains some value from the past. We don't know what that value is. When you say C in m and n the two values will come and replace whatever trash you had earlier. But you have not done anything to p. p will continue to have some trash value which will be printed. So if p for example contains minus 17345 then what will it print? It will print minus 13745. Now here is the curious possibility. Suppose this contains 9. What will it print? 9. Now what will you think? You once run a program with 7 and 5 it prints 7. Then you run a program with 2 and 9 it prints 9. You will think it is finding out the maximum. This should tell you that you should never test your program only with one data value. Or even with two data values because such initialization mistakes will not be caught. If by a freak accident this is an accident. See there are how many numbers possible exactly 9 to be there will be very unlucky for you. But suppose I am unlucky then I would like to remove the element of luck by running it again with say 2 and 11. Now I have to be very very unlucky if next time the location which is assigned contains 11. That is the reason why apart from testing you have to ensure that values are either initialized or assigned. No value should be printed which is a trash value. Is that clear? Of course the correct thing would be to say if m greater than n p equal to m else p equal to n if you want to find out the maximum. But there are occasions when you want to do something only if condition is true not otherwise. In which case you are welcome to do that. What are the possible conditions that you can write greater than less than greater than equal to less than equal to? Can I write equal to? No. If I want to compare whether m is equal to n very important. If you don't write it it will mean something else completely. And how do I say not equal to? Is this what I write? Exclamation mark. So please remember these are basic comparison operators. Now when I compare sometimes I want to write complex conditions. a greater than b and x less than y. So how will I write that? I will say a greater than b. Now how do you know that it will not do b and and y, b and and x. Because in comparison operators and logical operators there is a priority. And logical operator and or etcetera have a lower priority than this. However it is always safer, always safer to write this in a bracket, write this in a bracket. This is the well formed condition. And if you want to write an if statement you have to preclude it by one more pair of brackets. Because if statement requires a bracket under bracket pair in which you write it. And then you write your statement. Is that okay? How do you write or? This is where you write two vertical marks. And you can also write not of a condition by preceding it with an exclamation mark. So and or not these are the logical operators actually. Apart from if then else there is also a possibility of you are saying if. Sorry I thought somebody had a question. This is okay. If condition one what will be the meaning of this? If first condition is true you execute S1. If the first condition is not true then only you come down. Now you examine condition two. If condition is true then you execute S2. Else when you come here please note that both condition one is must be not true. And condition two also must be not true. Then only you will come. And if this condition is also not true then only you will execute S. So S4 will be executed. If condition one is not true and condition two is not true and condition three is not true. So depending upon how you want to write your logic you can use this. This is called an if else if ladder. So instead of writing complicated if this then if this then if this else this else this else this. You can use this ladder to compose your logic more correct. Is that okay? Suppose this is the problem you are given. Find the sum of the series 1 plus x plus x square plus x cube plus something. For some given value of x which is less than 1. By adding all those terms which are greater than 0.001. So suppose x is equal to 0.8. Now first term is 1 plus 0.8. Let me say for example then we have to add 1 plus 0.8. Plus 0.8 square. How much will it be? 0. Plus x cube. How much it will be? 0.5. 0.64 into 0.8. So how much is it? 524 or 512. Then in doubt? Do it the hard way. 64 multiplied by 8. 8 4's are 32. Carry 3. 8 6's are 48. 48 plus 3. 50 well. This is decimal point. This is decimal point. So 1 2 3 decimal point. 0.5 1 2. How did somebody get 0.5 2 4? I am very curious. And that's it. Please note the term. Term is x cube. So that's it. Anyway. Now we know two things. The terms are indeed reducing. So somewhere some term will become less than 0.001. After that I don't have to add. But I don't know how many terms I will have to add. I may have to add 200 300. 574 terms. I don't know. But I have to keep adding till a term becomes less than something. Right? So how will I do that? That is where I need iterative. I know each term. Each term is x multiplied by the previous term. Each term is x multiplied by the previous term. First term is what? 1. So now if I start with 1. And then keep adding new terms to the sum and finding new term. New term is equal to old term multiplied by x. If old term is 1. New term will be x. Next time new term should become old term. And this should be multiplied by x. So if I said term is equal to term multiplied by x. Every time I recalculate it. It will keep growing. This suggests to me that if I define float x term sum. And I set up an iteration of this type. I start by saying c in. Then I say term is equal to 1. Or if you want 0.0, better way of writing it. Can you check whether this program will work? First of all tell me whether you understand what this program will do. It is setting up an iteration. It says while term is greater than 0.001. Keep on doing this. What am I doing? This means what? I do two things. One, whatever is the term which is greater than 0.001. I add it to sum. And I prepare the next term for the next iteration. So I multiply the present term by x. It will become term into x. That is the new term. And when I go back to the next iteration. That term will be examined. If you have any doubt. You should always write values of term and sum. And find out what will happen. So let's execute this algorithm. Let us assume that c in as input is given 0.8. So I write term is 1, sum is 0. And x is 0.8. Agreed the first three statements. C in x will get you x as pointed. Term is equal to 1 will get you term as 1. Sum is equal to 0.0 will get you sum as 0.0. Fine? Now I come to while. While term greater than 0.001. Each term greater than 0.001 of course. It is 1. So yes. Therefore I go inside the loop. Inside the loop what do I do? Sum is equal to sum plus term. So what will happen? Sum is 0. Term is 1. This will be replaced by 1. Sum is equal to sum plus term. The next statement says term is equal to term into x. So what will happen to term? Term is 1. 1 into 0.8. So it will be 0.8. Now I come to closing curly bracket. Closing curly bracket means what iteration is over. Go back and check the condition again. So I go back and check what condition is term greater than 0.001. It is what is my term? 0.8. So I come inside the iteration again. This time what is the same statement is executed? Which is sum is equal to sum plus term. So what is sum? 1. Term 0.8. So what will be the sum? 1.8. Again term is recast. Term is equal to term into x. So this will become how much? 0.64. And again I come to the closing curly bracket. I am thrown back again. Examine term. Term is 0.64 greater than 0.001. Come inside the iteration. Sum is equal to sum plus term. This time it will become how much? 1.2. And next is term is equal to term into x. So how much term will become? 0.512. We do it just only this much. But we now confirm. 1. Terms are getting correctly calculated. And they are getting correctly added. So now let this iteration run. Let it calculate thousand terms. I don't have to do Godagiri of thousand additions myself. But program will work correct. So you see how such iterations are to be set up? Suppose I want to set up an iteration which will add n terms where n is given to you. Say n is 5000. Somebody says add 5000 terms. I don't care what is the last term. Add 5000 terms or add 250 terms. So if I have to do that, how will I set up the iteration? Let's go back to that slide. So what our friend is asking is can I directly use the match library which will find the exponential of x? What is the definition of e to the power x? Is it 1 plus x plus x square plus x cube? And naya exponential defined. Anybody remembers what is the standard exponential definition? e to the power x? x. x raised to the n at term is typically x to the power n upon n factorial bapa is a completely different series. In fact, you will not come to write a program if standard functions are available because for standard functions there are tables available also. Easy. And yes, you can use library functions in such cases. So cos theta, sin theta, e to the power x, log x. You can use this standard function. Many times what happens is that standard functions is not what you are interested in summing. That is why you have to use this. Second point, even if it was a standard function, suppose I pose it as a programming problem, standard function value will not fall from sky. Even for standard function somebody has to calculate. Now what you are saying is some joker has done that work some 50 years ago he has written something called library. Let me use it. Very good. But tomorrow if you have to be that joker whose work others will use then you should be able to write that program. And that is what we are trying to learn in this course. Of course we would like to use others program but we would like to learn to write programs ourselves. So now just because he has suggested this let us write a program to calculate e to the power x. But first let me complete this part. We will come to that problem also because that is an important issue. So same series 1 plus x plus x square plus x s to n but I want to add n terms of the same thing. There are two ways of doing this. First way I do the same thing. I say float x term sum. Now I have to add n terms. So I will define an integer n. And now since I have to do some counting I will define a counting variable say c. Now earlier what I did? I said c in input x. But I should also read one more value n. How many terms I want to add? n may be 5000, 15000 whatever. Please note that this is a simplified version. I would ordinarily say c out give value of n then c in n then c out give value of x then c in x etc. But this is a simplified one. So suppose these values are read. Now I have to do exactly the same thing that I did earlier that while loop is correct. But I have to add one more condition of counting. The condition is now not based on value of x. It is based on counting. So I will of course start with term equal to 1. Sum is equal to 0.0. But I will also say count is equal to 0. Let us say I start with count equal to 0. Now I put my condition while count. I want to add n times. My addition and term calculation is going to be safe. But let me try to put this here. C is initially 0. Let's say n is 10. So 0 is less than 10. I will necessarily come inside. I will add the first term that I have calculated earlier. Sum is equal to sum plus term. And then I recalculated term is equal to term multiplied by x. Earlier I was checking whether term was greater than 0.001. Now term has no role in decision making. I am counting. So obviously once I do something I should increase the count. Next time I do again increase the count. So I should also say c is equal to c plus 1. Now let us see how it will execute. Let us assume n is equal to 3. I want to add 3 terms. Let us confirm whether this will add 3 terms or not. First time c is 0. You come inside. What you are doing? Sum is equal to sum plus term. You are adding the first term. Now you increase the term. c becomes now c plus 1 which is 1. Is 1 less than 3? Yes. You will again come inside. Now this time you will add 1 plus x. Because term would have become x. Again c becomes 2. Is c greater than less than 3? Yes. Again third time you come inside. Term is added 1 plus x plus x square. Term now becomes x cube. c becomes 3. You go back. Is 3 less than 3? No. So you will come out. So it is correctly adding. The point is you want to do it 3 times. So you can count 0, 1, 2. Or you can even count 5, 6, 7. From 5 you can start counting up to 7. But since n is given the upper limit is known to you in terms of n. You can either start from 0 and count up to n minus 1. Or you can start with 1 and count up to equal to n. So as long as it is less than equal to n you can continue. So 1 to less than equal to n. Or 0 to less than n. Both are equal. Now the second way of writing this is all of this will remain same. Same, same, same. Here I will simply say term is equal to 1. Sum is equal to 0.0. And now I will say 4. Everybody understands this? This is the 4 loop counting loop. Note that there are 3 things specified in this loop. One is this, second is this, third is this. This is executed before you enter the loop. Only once. First time before you come to the fourth statement itself c equal to 0 is executed. This is exactly equivalent to doing it here. They are equal. C equal to 0 specifying here and writing c equal to 0 in a statement before you come to while is exactly. Next you check c less than n. That is the while equivalent. While c less than n do this. So the second part in the fourth is the condition. The third part is the increment part which is executed at the end. So whatever you have written here this is to be written here. So these are equivalent. Understood? This is very simple and a straightforward counting iteration. And in fact when we use arrays we extensively use this constraint. But there can be many variations in this constraint. For example the simplest variation is you rarely write c equal to c plus 1. What do you write instead? C plus plus not the c plus plus compiler but variable c incremented by 1. So find out what is the value of k that will be printed. What is your answer? Everybody. Why? k has not been initialized. Instead in this program I have stupidly initialized i which was not necessary. Because the fourth statement was going to initialize i anyway. But k which I am changing is not initialized at all. Of course can you say none of these always because of the bad luck factor. If that location for k contains zero then you may get the right answer. But that is chance. By and large none of these is the right answer. Now suppose I say k is equal to zero. Tell me what will be the answer? Now you have to do some work. Earlier was easy. So do it. Find out what is the value of k. Execute it. How much will it be? Ten. Ten. Pakka. Definite. Why? Tell me how you execute. The iteration is executed five times. And every time in that iteration k is incremented twice. So k plus plus k plus plus. So therefore two four six eight ten. If you have understood this counting you have understood everything. Because that is how the iterations work. You have to find out how many times that iteration executes. And those many times the internal statements will be executed. You will be able to find out. There is another form of iteration which is not very often used. But it is also equally important. And that iteration is of the type do something something something. This statement actually has this something followed by something followed by something done first. Then there is a condition check. And if the condition is true you go back here. If the condition is false you come out here. So what is the difference between this and the while? The while condition is checked before you enter the iteration. Here the condition is checked at the end of the iteration. So usually do is used when for the first time you necessarily want to execute the body of the iteration. You don't want to check the first execute then check. If that is your logic use this. If you want to the first check then execute and come back then you use why. And for fixed number of times you want to execute for. So these are the three possible choices. And once you understand the logic you should be able to figure that out. With this we now move over to discuss arrays. When I declare something like this what happens? 50 elements get allocated space. So a 50 stands for equivalent of 50 variables all of type integer. Array has to be collection of the same type. How is the first element identified of the array? And the last element is identified as the important point is that C++ says that you can also write a j. Whenever you write j it means whatever is the value of j you are referring to that. So if j is 5 you are referring to a 5. j is 0 you are referring to a 0. j is 49 you are referring to a 49. j is 500 what are you referring error question what will happen? What does C++ do sorry garbage value from where? See garbage value is used in your program if the location that you have defined has not been initialized by you. Some old value will be there but a 500 some old value where? Earlier it was a n or x or something so there is a location what is a 500? The location itself is not defined so what will C++ do? No it will not show an error. He is right but he is not completely right. What C++ does is important to understand. C++ does not show an error. C++ unfortunately while executing your program does not do checking whether your index is within the range 0 to 49 or not. That is your responsibility. What it says oh you say a 500 this is a 0 this is a 1 a 2 a 3 a 49 a 50 a 51 a 52 and go that corner a 500 somewhere here some location. In this location you might have a floating point variables here then it will pick up that value. This location may not be in your program it may be his program he is executing something and he has some n or something or some p or whatever. Now if memory is not protected your memory and his memory separately for computer is all one memory. So you will say aj is equal to minus 5 and in his program some variable will become minus 5. Is that okay? May be okay for you but not for him. So that is why computer systems protect programs and they say this is your segment of memory that is his segment of memory. And you cannot go into his segment of memory. So that is why you sometimes get a fault called segmentation fault. Segmentation error segment means you are exceeding. This is your house that is his house. You are not permitted to eat in your house and go there to sleep. You have to stay in your house. So segmentation fault. But if the index is exceeded by some small value typically by one value say it becomes instead of 0 it becomes minus 1. Instead of 49 it becomes 50 then invariably you will still be within your segment and it may create a problem. So your responsibility to ensure that the array index always remains between 0 and maximum limit minus 1. That is your responsibility. Understood? Never make this error. So particularly when you say j and such things then you have a problem of this kind. Let us now consider this array and my problem is put in values in successive elements of this array which is 5, 10, 15, 20, etc. That means there is an array. You have declared an array. Now I want you to write a program which will put these values. 0th element it will put 5, next element it will put 10, next element it will put 15, etc. How will I write a program? Okay. So I have let us say this will go through all the elements. Please remember for an array if you want to scan all elements or if you want to do something with every element. The simplest thing is to set up a loop for some variable equal to 0 to n minus 1. So j less than 50 means this loop will execute 50 times 0, 1, 2, 3, 4, 4. That is 5. Now I have to say something like a j equal to how much? First time when it executes the iteration what should be the value j equal to 0? Yeah but what should be the value of a 0? 5. Next time it should be 10. So it is increasing every time. 5 multiplied by 1, 5 multiplied by 2, 5 multiplied by 3, 1, 2, 3, 4 is 1 greater than j which is 0, 1, 2, 3. So suppose I said j plus 1 into 5. Will I get the correct value? Did you all think of this logic? No. That is the point. That is the way you have to think that I want to get a series 5, 10, 15, 20. Then that series what is the nth term or jth term? Jth term is j plus 1 into 5. Once you get the jth term you assign it. So this is how you can manipulate arrays. Is that clear? You can also scan arrays. So how do you find the maximum element in an array? Just tell me whether this part of the program will read n elements in the array or not. I am reading the value of n and I am setting up a loop for i equal to 0 to n minus 1 input ai. There is only one problem. As a professional programmer after reading n, but before setting up a fault loop, I should check whether n is less than 5,000 and n is greater than or equal to 0. If n is less than 0, no problem. The loop will not execute it or nothing will be read. But if n is 10,000, I will have a problem. Same segmentation fault. You are reading values and putting those values in his house, not permitted. So that cross check you can do, but otherwise programming wise this will work. Now I have to find out the maximum of these n elements. It is a very simple thing. I can start with max is equal to arbitrarily the 0th element of the array. Then I can say for i equal to 1 to i less than n i plus plus if with this logic work, what we are doing is starting with max equal to 0 and then going through all the remaining elements 0, 1, 2, 3, 4, 5, 6 and if any one of those elements is greater than the current max, I replace max by that. So I have found that. Now I will give you a slightly complicated example. Let us say this is the last example we discussed. Read this problem and understand and tell me what have you understood. Try to construct a small example. Given an integer array which contains integer values, print those values which occur more than once in the array. That means all values are not unique. So let us construct an example. Let us say the array is 1, 12, 5, minus 7, 12, 12. So this is an array. It contains some integers. You will notice that 1 happens to be only once. 12 happens to be three times. 5 happens to be twice and minus 7 happens only once. So now what is the problem? Problem says those values which occur more than once. So which are those values? 12, 12, 12 and 5, 5. So print those values but print each value only once. How will you solve this? So what he is saying is take one value and examine whether that value occurs in my entire array. If it occurs once, then count will be 1. If it occurs more times, count will be more. And if the count is more, I will print it. So suppose I follow this logic. Have you understood this logic? I will take each number separately. I will call it say element E. And I will see if E is there, there, there, there. Now somewhere it has to be there because I have picked up. But I will scan the entire array. If it has occurred only once, count will be 1. If it has occurred many times, count will be many more. So I will assume that I have read any elements into the array. Like we had done that just now. Now I start this. So I am looking at each element of the array in succession. I have to look at 0th element, then 1st, then 2nd, then 4th. Whichever element I am looking at, I am assigning it temporarily to a variable called EL. So EL is the element which I want to examine. If you look at this array, 1, 12, 5, minus 7, 12, 12, 5. I will be examining 1. Then I will examine 12. Then I will examine 5. Then I will examine minus 7, 12, etc. Each one inter. And what I am going to do examination means take that element and check whether it exists anywhere in the array. So I want to, with respect to this element, I want to scan the entire array again. And wherever that any element is same as this, I want to increase the count. So I will set up another iteration which goes through the entire array once again. I will say now for j is equal to 0 to j less than n, j plus plus. If EL is equal to aj, count plus plus. Do you see what I am doing? I have taken one EL. So for example, suppose I am somewhere 1, 12, 5, minus 7. Suppose I am at minus 7. My i is 0, 1, 2, 3. For i equal to 3 EL will be what? Minus 7, a of minus 3. Now with minus 7, I start scanning the entire array for j equal to 0 to 7. So I will check. Is minus 7 equal to 1? Is minus 7 equal to 12? Minus 7 equal to this? So if somewhere minus 7 will be equal to minus 7, count will become 1. Initially count was 0. Suppose I am examining 12. That is my i is equal to 1. When i is equal to 1, EL is how much? A1. A0 is 1. A1 is 12. So EL is equal to 12. Now with EL equal to 12, for example, for i equal to 1, EL will be 12. And I run this loop with EL equal to 12. Now what happens in the inner loop? J is equal to 0 to n minus 1. All elements are checked against EL. Is EL equal to EJ? So is EL equal to A0? No. Is EL equal to A1? Yes. Count will become 1. Is EL equal to 5? No. Is EL equal to minus 7? No. Is EL equal to 12? Yes. Count will increase one more time. That means when I come out here, Count is 1, then that element has occurred only once. If Count is more than 1, then that element has occurred many times. So if Count equal equal 1, then the element has occurred once. Else, right? Now I have got two portions of my program. Count is 1, it has occurred only once. If Count is more than 1, it has occurred many times. I could simply say in my program here, if Count greater than 1, see out EL. I will print that. Print those values which occur more than once. My problem is solved. Second part of the problem is not easy. Print each such value only once. Imagine I start with 1, it will not be printed because 1 occurs only once. When I come to 12, 12 occurs three times. My Count will be 3, I will print 12. Then I go to 5. 5 occurs twice, 5 will also be printed. Then I come to minus 7, it will not be printed. But then I again come to 12 and with EL equal to 12, I go back to 0th element and again say 12 is there, 12 is here. Count is 3 again. Again it will be printed. So 12 will be printed. Three times 5 will be printed twice. I have solved this problem partially, not fully. Sorry? Come again? No, break where? If I break I will come out and I will not examine any element after that. And suppose there are some other elements I will not get. So this is a hard problem. This is a hard problem. What you will have to do is you will have to sort the array. Assending, descending, all of whatever. Now you examine successive element, 0th element, first element. Are they same? No, they are different. They are different means that element is occurring only once. Forget that. Go to the next. Go to the next. But suppose you now find, oh the next element is same. Now you stop there. You found a fellow who is occurring many times. You print that fellow. But continue the checking. This fellow is same. Is this fellow also same? Is this fellow? Because when you sort, all the same elements will come together. Now if 12 occurs three times, it will come together three times. Then only some other number will come. When the next number comes, you forget this and start checking again. However, if the problem is only this, then you can do this here. If the problem is it says print those values which occur more than once. Why? You are printing it three times. But that value is occurring more than once. So your answer is right. Suppose you have to print the values which occur only once. Then what will you do? Sorry? If count equal equal 1, see out that element EL. And that will happen only once so that you have no worry about. You will never find it again. Suppose I said you take the values which occur uniquely and find their sum. That means in this given problem, I want to find the sum of 1 and minus 7. Because 1 is unique, minus 7 is unique. What can I do? First I define sum equal to 0 outside somewhere. Now I do the same logic. If count equal equal 1, sum is equal to sum plus EL, that element. Not see out here. I will complete that J loop, I will complete high loop and afterwards I will say sum is equal to this. So it's easy, right? Everybody understood how you handle this? Okay. There could be any number of squiggles or complications that may arise out of this. But essentially if you understood the logic that you may have to scan the array elements one by one. You have to use a loop. For a given element, you may have to again scan that array or some other array. You have to put an inner loop. And you may have inner loop, inner loop as many times as you want. The logic is that you should be careful about what is I, what is J, what is K, where you are using index. And the logic should be when you should do what? For example printing that sum. You can't print the sum here. This is inside this I loop. So you close this I loop also, you find the sum. But print this sum outside. Because you have to calculate the sum of all elements which are unique, no? So you have found out only one here right now. You added it to sum. When I changes, you will find some other element. All such elements will be combined only when you finish this. And here you should print that sum. Is that understood? I think we will stop here.