• 2 days ago
Transcript
00:00Hello everyone, this is Sandeep. Now I am going to explain this sixth number program
00:09and what the program is let us see. Input five numbers in array then copy it into another
00:16array in reverse order. So we have to copy the elements of first array into second array
00:27and that we have to copy in a reverse order. So how to do this let us see okay.
00:35I am going to make the program. First thing what I will do, I will store the values, I
00:47will store the elements inside the first array okay. Let us quickly give the name to it to
01:00the program okay and save it. I will use what int main and inside it I will first of all
01:15declare two arrays A having five elements and one more array B which is also going to store
01:24five elements. I will take two extra variables one is I another one is what J okay. Now I will
01:35give a message here that is to store the value inside the first array variable and put the values
01:43inside first array okay. We are going to store the five elements inside the first array. For
01:59that I will apply the loop I equals to zero I less than five okay I plus plus like this.
02:07Then scanf inside the inverted comma percent e comma and a I. So the loop will carry on for
02:25five times and the values are going to store inside the A array. Now for the logic part I
02:33would again apply the loop I equals to zero okay and J equals to four like this as I have to
02:45initialize both the values of I and J okay. So I will use the comma then I less than five okay.
02:55So what I plus plus comma J minus minus okay. So one of the loop is in an incrementation form
03:07and another loop in decrementation form both I have used inside this for loop and what I
03:15will write down here a J equals to a I. So whatever the value which is there inside the
03:26index position of I that is going to store inside the index position of J okay. Once all the things
03:35will be done all the values will be stored inside the P array in the second array okay
03:43and we have to display it. So for that int have values or numbers stored in reverse order okay.
03:58For that for I equals to zero I less than five I plus plus okay and then we have to display it.
04:14So what int f person D comma B I okay. So the resulted value is inside the secondary B okay
04:39and then it's going to display. I give some space also so that after each value there should be
04:50space okay and here I should use slash n so that I should input the value from the next row okay
05:07and here also slash n. Let us save, let me run one time and then I will see is it going to give
05:17the correct result or not. Here it should be what semicolon as it's giving the error let us see
05:23what the error is showing. Error which it is showing is that semicolon before this basis
05:32okay. So I haven't used it, I will use it. I will click on build so it's showing me zero
05:39and zero warning. Let us run. So I'm going to input the values inside the first array five
05:46three one okay two like this one more four. It should show me in a reverse order so it's
05:59showing me first four then two then one then three then five okay. So the execution is fine
06:08the program is right okay. Now we have to understand how it's going to work. So I have
06:15applied the loop to input the values inside the array okay all the values are stored. Suppose
06:20the values are these three six seven two and five. So I have carry on the loop and the values
06:29are stored inside the array okay. Now I have again applied the loop for loop okay and inside it
06:37here if you see I have to see the logical part the value of i is what zero okay the value of j
06:45is what four okay and it will come to the decision part zero less than five the condition is true
06:52when the zero is less than zero is less than five the condition is true. So what we are doing the
06:59value which is there inside the zeroth index position we are going to store inside the fourth
07:05index position of the secondary okay. So let us see what is value there inside the zero index
07:16position and the zero index position it is three okay and that value is going to store inside the
07:26it is going to store here inside the fourth index position here okay. Then the value of j
07:41is going to decrement from four it will be what three and the value of i is going to increment
07:48from zero it is going to what one. One less than five the condition is true what is there inside
07:55the first index position of array and the first index position of an array it is six okay and
08:07what is there the value of j it is three so the value which is there inside the
08:19first index position that is going to store inside the b array okay third position okay
08:27inside third index position. So from the first index position of a array the value is going to
08:33store inside the from here it is going to store here okay I just indicate to here.
08:42So in this way I hope you understand in this way this loop is going to carry on
08:48there will be decrement of j and there will be increment of i okay and in this way the values
08:56is going to store in the in the reverse order inside the secondary okay once the loop will
09:04terminate this loop will terminate okay. I have again applied the loop to show the values inside
09:11the b array in reverse order so I have displayed I have used a printf to display the message that
09:21is values stored in reverse order in this in the secondary for that I have applied the loop
09:26on where when the values are going to display okay. So I hope you understand it
09:32in the next video I will explain some another program. Thanks for today.

Recommended