Hi everyone.
So in this video we are going to solve this question print all the prefixes of a given string.
So this is the input string and we have to print all the prefix of the given string.
So for example in this case our output should be.
So the first prefix is a.
Then a B then ABC then ABC.
So these are all the prefixes and we have to print all these prefixes.
So how can we do that.
So it is very obvious solution just simple implementation problem.
So this is your input string and what are you going to do.
So this is there not index zero index 1 2 and 3.
And similarly for so first you have to print a.
So that means you have to print from index to zero.
So what is a A's start printing from index zero 0 and Brent Bill index zero that means only one character
for a b what I'm doing.
Start printing from index zero.
And Brent build index 1 including index 1.
Similarly for printing ABC what I'm doing.
Start printing from index zero.
And you have to print Bill index to so and including index to avoid printing a B.
So ABC this will be ABC.
So what printing obesity.
Start printing from index zero.
And you have to print build index 3 and obviously including index 3.
So just you have to do this small amount of work and if you notice the starting point.
So can I say this is the starting point the starting index and I can say this is the ending index.
So this is the starting index which is constant 0 0 0 0.
And this is the ending index which is going to be already able.
So how can this all this caution.
Again I told you just this is just implementation volume.
There is no logic in this question.
You just have to write the code.
So what do you do.
This is a beauty you will take a variable.
And so this is.
And so what Andrew Louis does start from zero.
And we go to three.
So when and is that dissipation what do we do you will start.
So either start will become I will start for this start from zero always.
So what I will do I will start printing from index to zero so I will need a for loop so this loop will
start printing from index 0.
And index simple so you need to loop so when loop is actually loop for and index.
And the second is in that most loop.
So this loop will start from these stodgy nicks and it will go Delta and index simple.
So let us write the code and you guys can understand it better that we so let me remove everything from
here.
Don't worry I will give you the code probably.
So what we are going to do let us create the function that the function is going to be void because
we only have to print.
We don't have to do anything else.
So the name of the function is print all prefixes
so what we should do what it will take as input and it will take a character as input let's call it
string.
So I'm digging a string as input so I need doing almost to loop first is the outer loop I'm calling
it.
And so and we'll start from zero.
You can write like this and this SDR alien of SD odd.
So this is the first option.
The second option to write is you can write like this string off end is not close to the null character
more tired of it than you will do and plus plus.
So my End Point is our trading and now I need a pointer so my start point it will start from zero and
the start will go till end start listless.
I will print so see out s.t. out of start
simple and head I will write C out and lean and now let us call this function.
So first let us create a string so string SDR.
So let's say the string is a b c d and now it's time to call the function and best Delta program.
So the name let's copy the name print all prefix i will give the string as input and I think of a code
should work fine.
So let us test our code
and these are all the prefixes a a b ABC and a b c.
So now let's try to understand how the code is working.
So as discussed efficiency I knew to loop.
So this is the end.
And this is the start.
So and we'll move in this direction and you will start printing from index 0 in the end index so just
simple when the.
So let's get started.
So what I'm doing.
This is an index so this is index and so this is index n.
So initially the value of index and is 0.
It is starting from 0.
I haven't nicked it start so index start is initially zero.
Check this condition and start this list in articles to end.
Yes print the correct bet so I will print correctly now start will become 1.
So this condition will become false if this condition to become false.
Go to the next line.
So I will go to the next line.
Now the value of fandom will become one because we have written and a plus plus.
Then you start will again start from zero.
You will print e then it will become one.
So you will print B then it will become do so as soon as it becomes 2.
So this condition will again become false and it will go to the next line C out and line.
Similarly the value of an index will become two because this is and plus plus the value of start will
become zero you will print a the values type will become one you will print to be the values that will
become two you will see the value of start will become three and you will stop because this condition
will become false then you will go to the next line again the end index will become three because you
have written and plus so the start will start from zero.
You will bring to E and it will become one you will bring to B.
It will become too you will print c it will become 3 you will bank D then it will become fold.
So 4 is good then 3 and you will stop.
So this condition will become voice and you will stop.
Then you will give C outline lane so you will go to the next line.
So that's why there is a line here that's why there is a line coming out here.
So then the value of and will become 4 and at Fort index you can check it will become equal to the characters
or the string is ABC.
You can see the string is actually ABC and at index forward so this is indexed would add to next world.
My electric base did so if the value of and is for this condition will become false and basically you
will come out of the for loop and basically my function the vocal function is a what.
And this is my output so that's how this code is working.
So I hope you guys can understand this code.
So if you have any doubt and discussion you can definitely ask me and one modification of this question
can be.
So what we are doing we are printing all the prefixes we have printing all the prefix.
So the homework for you guys can be read you can do you can print all that suffix.
So for example the input is a beauty.
So what will be all the suffix.
So it will be B.
Then it will be CDE then it will be writing b c and then it will be ABC.
So I hope you guys can do this.
So we are printing all the suffix head print all suffix
so again first you have to print this character then you have to print these two characters then you
have to print these three characters and then you have to print these four characters and print all
prefixes.
What you are doing.
If these string is ABC first you are printing this character then we were printing this then you are
printing this and then we were printing this so the logic is going to be seen.
Again I am telling you this is just the implementation problem if you ever try and write.
If we tried to write the code for this problem according skills we will improve a lot to according skills
will improve a lot.
Again if you have any doubt in this question being double prefix are you encountered no doubt in this
quotient and also fix.
You can definitely offscreen that Q and A section so I will see you in the next video.
Bye bye.