Hey, guys, what's up?
So today we are going to solve one more interesting pattern, printing problem.
So write a program to print.
Below baktun.
So four and equals five.
My pattern would look something like.
OK.
So four and equals five.
I have to print this pattern.
We have not solved this question before, so let us all discussion for the first time.
So here the real fight is when I used to I used three, I use four and I use five.
So one thing is very clear here.
I need a loop that will run and times because you can see here the value of this fire if I am printing
five rules.
So I need a loop and this loop will run and times.
Okay, now one more thing that we here.
If the value of fire is too.
I am beginning to lose the value of history.
I am renting three.
We're losing the value of I is four.
I am renting for values and so on.
OK, so one thing is very clear here, footprinting a year through for printing, a year through.
I have to print a numbers.
OK.
So Androes for printing, I for printing, I drew through, I need I need to print eye numbers.
One more thing here that we are, we have observed this.
If I is even if I easy when I am starting from zero.
So we can see if the value of AI is even the first number is zero of the value of AI is even the first
number is zero.
And if the value of AI is on, my first number is when, when and when, if the value of AI is odd.
So if the value of AI is odd, I will start printing AI yetto from when, otherwise I will start printing
from zero and I have to print AI numbers and each time I have to change the number.
If I have print zero nine next time I will print one.
Next time I will print zero.
Next time I will print one.
Similarly, if I have printed one, the next time I will print zero.
The next time I will print one.
The next time I will print zero.
So basically they will be swiping between zero and one zero one zero one or one zero one zero.
So.
I equals one vial.
I is less than articles to N and I C++.
So this outer loop is for running the loop and times because we have to print Androes.
Now I will check if I Yeah.
Through is even if they throw on dividing by two gives a window zero that means I is even.
So my first number is going to be zero.
So when two equals zero else we can see my first value is going to be one.
Okay.
So this thing is clear.
And now what we have to do.
We have to print iron ambo's.
We have to print eye numbers.
So since we have to print eight numbers, we need a loop and this loop children eight times so and count
equals one.
While count is less than articles to a
count.
Plus, plus.
And here I will friend my value.
Now I have to change the value.
So what I will do if the value that we have printed is one.
Then make value zero.
Because next time we have to print zero.
Similarly elusive, the value that we have printed now is zero, then make value one, because next
time we have to print one.
So why I am doing this because we have to print alternate zeros and ones.
Okay, so we have to print alternate zeros and ones.
So that's why I am checking if the value that we have printed is one.
Make it zero so that next time I will print zero.
If the value that we have printed now is zero, then make it one.
So that next time we will print one.
Well, guess what?
This is the entire logic.
Now, let us write called.
So let us name this file as.
One zero baktun.
OK.
You know, the first thing that we have to do.
I will take an as and put fundi user simple.
Then I will need a loop that will run and times because I have to print and rose.
Now, this loop will run and times.
Now, first of all, we have to decide which way do we have to print first?
Okay, so if the I yet rule is and even Drew, if the eighth row isn't even true, I will start my first
value that I will print is going to be zero.
Otherwise, as my first value today, I will print is one simple.
So let us make
our variable and will.
Okay.
So you can see here.
So you can see here, if the value of I was too low, if I was even my first number was zero.
If the value of I was offered, my first number was one.
So I have initialized my value.
So I've initialized to my value now what I have to do.
I will run a loop, I Adames, because we have to print eye numbers, okay, because we have to print
a numbers.
So I need a loop that will run eight times.
So let's make a variable and count.
So we have to run the loop eight times.
So count less than or equal to a count plus plus simple.
And now here we have to print sea out value.
But this is not enough.
Where do we have to do after printing that value?
If the value was one, we have to make it zero.
If the value was zero, we have to make it when.
OK.
So if the value that we have printed is one where we have to do make it zero, value equals zero because
we have to print alternate zeros and ones else.
If check if the value net we have printed is zero.
Then we have to make this value one because next time we have to print one.
OK, so this is the end bad logic.
Now, let us based our program.
OK, over here, semicolon.
Now let us test our program.
Let's say, and there's three.
OK, so what is the mistake here?
So the mistake is very common after printing.
So after printing the numbers, after printing one entire drawer, I have to go to next to do so see
out and Lane.
Now, this is correct.
Let's say they're really off.
And there's three.
Again, with outproduce, correct, not a distaste.
One more time.
Let's say the value of an is five.
So now four days.
Correct.
OK.
Now, what you can do is.
So instead of writing this, we can also write like this.
So value equals.
When my nose value.
OK.
So they both ask him this thing and this thing, they bought the same.
Let me show you.
So if the value of an is five, some output is correct.
OK.
So they both are the same.
Now, why the you ask him now?
This thing was obvious.
So what it was doing, if the value is when it will make value equals zero.
Similarly, if the value is zero, it will make value equals one.
Now this line will also do the same book.
OK.
Suppose value equals one minus value.
So first case, suppose the value is initially one.
OK, so put one here.
So one minus one zero.
So new value will become two.
Now suppose the value is initially zero.
Now put zero here.
So value equals one minus zero.
So new value will become one.
So you can see here it is also changing the values.
Obviously, this line and this line, the bow tie.
Same you can write any one of them.
OK, so I recommended this out for the reference that this line and this line.
They're both the same.
OK.
So this is it for this video.
Thank you.