 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can print reverse of adding in C programming. So I will be explaining three different methods so that you can print reverse of adding. So these three methods will be related to C programming. Do watch the complete video so that you can get to know how we can use three different ways to print reverse of adding. Before starting just one update, if you go to a detailed description of this video, you can see various links of a playlist related to C programming. So you can follow them if you want to watch more programming later in the video. Now I'm going to explain method number one first. So first of all, I'm going to read one. So this is the declaration of adding along with one variable line. Now to read that vehicle from user, I'm going to print this message. Then I'm iterating a loop which will run 10 times and it will read 10 different numbers. And those numbers will be stored inside a right. So these three statements are for reading area from user. Now after reading all these 10 elements, now I'm going to tell you method number one, like how you can print those elements in reverse on. So let me first explain the meaning of reverse. So let's say this is an array and it is having these values and these are the indexes. So these are values and these are index. Now the output of this will be 20, then 19, then 18 and so on. So this means the words. So reverse means first we need to print the last element of array, then second last element and so on. So now after this reading, I'm going to print a message, reverse of any and after this message, I'm going to print each element starting from last. So I'm going to use a loop which will start from line. I'm going to start a loop which will start from line. Then its condition will be I greater than equals to no. And then I just write sorry, I minus minus. And then I'm going to write printf backslash and person D and here I can write E of I and closing off main function. So here you can see I'm starting from nine. So nine is this position. So value of I is nine, which is greater than equals to zero. So this printf will print A of nine. So A of nine means 20. So first 20 will be printed on output screen that I minus minus I will become eight. Check this condition. It is again true. So this time it will print value of eight index that is 19. So 19 will be printed on output screen. So this way this loop will go to zero because last index is zero. That's why I placed greater than equals to then value of I will be minus one. Then this loop. So this way you understood the method one that is printing all the elements of array in reverse. So in this method one, I can also change this loop so that it will start from zero and it will go to nine and still it will print the reverse. So I'm changing it starting with zero condition is I less than 10 and here I'm using I plus plus now see carefully what I'm going to do. I'm putting this A of nine minus I so see it carefully now I is zero at the beginning condition is less than 10, which is true. Now solve this nine minus I so I is zero. So first time it will become a nine. So a nine means 20 will be printed on output screen. Then I will be incremented to one. So next time a nine minus one. So it means it will provide A of eight. So A of eight is 19. So 19 will be printed on output screen. Then I will be incremented to two. So nine minus two will be seven. So this way with this expression, you are able to identify other indexes in reverse order so that we can print array in reverse order. So this way, along with method one, you can use two arrays. You can start it from zero to nine, or you can start it from nine and you can terminate it to three. So I hope you understood the method one. Now I'm going to explain method number two. So I'm removing these statements. So in method one, you saw that the value of array is still in the order which is provided by the user. We are just we just printed it in reverse order. We didn't change the elements order actually that is available inside the array. Now, if you want, 20 will be available at zero position, 19 will be available at one position and 11 will be available at last position, 12 will be available at second last position this way. So in that case, we can use method number two. So I am going to declare one more variable as array that is B. Now, here I'm going to write printf reverse of array that again for you. So it will be 10 times from zero to nine. Now I'm going to assign, I'm going to assign this zero index at last position of secondary. So let's say this is secondary, its name is B. So you will see 11 will go here, 11 will go here and this way it will be having reverse of A. So we need to store elements in B from A. So here we need to put indexes so that we can assign values. So we are starting from zero. So I'm putting A of I, right now this A of I means A of zero position will go to A sorry B nine. So here I'm putting nine minus. Now let's solve it. Initially I will be zero. So a zero position that is 11 will be assigning to be nine minus. So I is zero. So it means B nine. So B nine position will be having enough. Then I will be committed. I will be one. So a one that is 12 will be assigning to be eight because nine minus one I is one. So eight position will be having 12 next time I will become two. So A of two position is 13 and nine minus two is seven. So 13 will move here at seventh index of B. So this way we are copying individual elements of A area from the beginning and putting them into B area starting from R. So this way B area will be having all the elements in reverse on. So I'm closing this after completion of this. I can rotate one more starting from zero to 10. And this will print the elements which are stored in B area and I index. So after complete rotation, it will be having values like this. It will be having values like this. So A is having values in the order which is provided by the user B area is having all the elements in reverse order. So B is having reverse of A. Now I'm going to print B. So I is starting from zero. So B zero will print 20 then B one will print 19 then 18 and 17. So this way reverse of A will be printed on output. So this was method two. So in method one you saw the drawback we were just printing elements in reverse order on output screen. In actual memory we were not having reverse of A but in method two we are printing reverse of A on output screen as well as we have the reverse of A in memory as well. But here you can see we have two arrays. We have two arrays. So it means we are wasting memory if we are using the second. So this problem will be resolved by method three. So in case of method three, you will be having reverse of array printed on output screen as well as reverse of array in memory and you don't require any extra array. So what we will be doing, we will be doing reverse of this array in internally in memory. So I'm raising this and now I'm going to tell you how we will do that. So I'm removing this as well because now we don't require any additional array. So we will be having variable i and variable j. Now I'm going to explain requirement of method three what we are going to do. So we are going to swap elements. We are going to swap elements first and last will be swapped then second and second last third and third last fourth and fourth last and fifth and fifth last. All the elements will be swapped. So if we swap these elements, so 20 will be available here and 11 will move here. So this way we don't require any extra memory, any extra array and within the same array you will be having the reverse of array and then you can print that array on output screen. So this is my method number three. So now I'm going to implement the logic for this. Then I will explain how it will be working. So here I'm writing one loop that is starting from zero. Then I'm placing comma and putting j equals to nine. So see carefully here I'm using two variables for initialization purpose and I just provided comma in between not semicolon semicolon will come after this. Now I'm writing the condition. It is I less than j. So loop will repeat till I is less than the value of j. Then I am going to increase value of i comma. I'm going to decrease value of j. So again to increment or decrement operation. So I'm putting comma in between and before that I am using semicolon to remember that we can use multiple variables for initialization. We can use multiple variables for increment and decrement operation. Now here I'm going to swap values of these two locations. So I'm going to use one more variable as t and really variable. So here I'm writing this. So this way this loop will perform swapping of adding so that we can have reverse of it. So now be with me so that you can understand how this process will go. So initially I will be zero and j will be nine. Initially I will be zero and j will be nine. Check this condition. It is true. I is less than j. Perform this. So this is simple swapping operation. We using third variable. So the A of i will go to t, A of j will go to i and t will go to j. So it means I hope you already know how this swapping operation works. So 11 will be replaced with 20. This will happen with this logic. And if you want to know this as well. So I'm explaining this A of i. So initially A is zero. So A is zero was 11. So initially it was 11 and it was 20. So I'm going to explain this for first rotation only so that you can understand this. So A is zero is 11. So t will be 11. Now a j, j is nine. So a nine index is having 20. Which will go to a zero position. So a zero position will be 20. Now we need to assign t into a j. So a j is nine. A nine. So this position will be having 11. So this way we are swapping two elements with this one. Then i will be implemented to one and j will be decremented to eight. Check this condition. And I hope you understood what will be the next step. We are going to swap two elements. So element that is available at one index and available at eight index will be swapped. So one index is 12. Eight is 19. So this way it will swap. Then i will be two. J will be seven. So here it will be 18 and here 13. Then i3 and j will be six. So three is 40 and six is 17. So 17 will be here and 14 will be here. Then i4 and j5. Right. So 45 will disturb. So here 16 and then 15. Then i will be five and j will be six. So now check this condition. So it will be four because we need to decrease j. So j will be four. So now check this condition. I is five and j is four. So this condition is false. So in this situation, this loop will be terminated. And here you can see Eric is arranged in reverse order. So 2019, 18, 17, 16, 15, 14, 13, 12 and 11. All are arranged in reverse order. So we did only five rotation of loop. And with five rotation, we swapped 10. Because in one rotation, we are shifting position up to it. Right. And after this, you can print a message reverse of Eric. And then you can start from zero and nine. And with this loop, you can print the value of. And then you can close your main function. So this way this area will be printed on output screen with this loop in reverse order. So method three is explaining how we perform reverse in memory as well. And we printed reverse on output screen as well. So I hope you understood each method method one method two and method three. So each have their own advantages and projects. So there are three various methods so that you can print a reverse of Eric on output screen. So try all them in your laptop so that you can understand how they are working. And if you watch more programming related videos. So again, you can open my channel, go to playlist. There you will see various videos available. And you can also go to detail or description of this video where you will be having a playlist related to C programming. And I hope you understood whatever I explained in this video. So thank you for watching this video.