Hello, guys, and welcome back to the goods.
So in all our previous classes, we were drawing different shapes like Rectangle Diomande pilot program
to show the steps that are involved in solving a problem.
Basically, we were drawing flowcharts.
But from now on, we will never draw flowchart.
Why?
Because today we are going to learn pseudocode.
So before discussing pseudocode, I want you to answer me a very simple question.
My question is, what is our ultimate aim?
What do we want to achieve?
So our ultimate aim is to somehow show the steps that we have followed.
To solve the problem.
And in all our previous classes, we were showing these steps with the help of flu shots.
That is with the help of different shapes and arrows.
But what sort of courses, if your aim is to just show the steps.
Then you can simply write structured English, showing the steps.
And there is no need of growing the friendships.
Makes sense.
OK, so let's compare with Jordan to look for side by side.
Flowchart pseudocode.
OK, so if MoD's is good, then took pity.
If this condition is true.
Bengt.
Bus.
And if this condition is false, then bent field.
So what will be the corresponding so-called.
If Max is a good identity, then bent pass bent feis.
As Peñafiel.
OK.
So if Max is good, then 33, then Brent pass and Sprint fail.
So they both are same.
They both are him.
OK, so let's see one more example.
Suppose I want to print hello five times.
What will I do?
I will use a loop.
So I equals one.
Is I less than ordered close to five?
If this condition is true, I will print hello.
And I will increase the value if I buy one.
So I equals a plus one.
And then I will check the condition again.
And if this condition is false, you can endure program.
So the first part is initialise.
The second part is to check the condition.
Third parties to do some work.
And the fourth, you can say, is update.
Similarly, initialise.
So I equals one.
This is how the initialise.
OK, so I equals one way.
I is less than articles to five do what do I do?
I will bring telo.
Brent, hello, and increase the value if I buy one.
So I equals a plus one.
And at this point of time, my loop will break.
And I have printed halophiles times so you can return.
Return means you can end your program.
So return a Seimas and.
This is same as I was when.
So this is my condition.
And this is update.
OK, so the border seem so you can see here.
So the gold is much, much simpler than flowchart.
There's no need of bring the friendships.
You can simply raid structured English.
So we all know how this is working, how this will print Halo five times.
Now let's see how this will look.
So initially I equals one, OK?
Then it will check the condition is one less than goes to face.
The condition is true.
It will print halo.
OK.
And then you will increase the value if I buy one.
So the new value of AI is two.
And then you will check the condition again.
Is to less than close to five.
So the condition is true.
You will bring Telo and then you will increase their live fire by went to the new vilify as tea and
then you will check the condition again.
Is three less than was to five?
So the condition is true.
Brent, hello.
And then you will increase the value of five Bevan's the new value of I will become four.
Then you will check the condition again is for less than Agosta five.
So the condition is true.
You will bring Telo and then you will increase the value if I buy one.
So the new value of FI is five.
Then you will check the condition again is five.
Letter was to five for the condition is true.
You will print hello and then you will increase the value of five beavan's to the new value of I will
become six.
And then he will check the condition again.
So is a six less than close to five and six less than close to five?
No.
Then you will come out of this loop.
So this is my loop.
You will come out of this loop.
You will reach here and here I ever done.
So it means.
And their program.
So I will end the program.
And hello.
Sprinted five times.
And similarly, this loop is running five times.
And each time I am printing.
Hello.
So in total.
Hello.
We printed five times.
Now we will be solving four problems.
And this time we will be writing pseudocode and Stewart over bring flowchart.
So problem one, probably one statement is.
Given an.
If it is prime are not.
So if you remember, we have already covered this problem in our previous videos Maddin that we use
and that lessons we have drawn the flowchart.
But today we will be writing sort of code for the same.
OK, so what was our logic to check whether a number is prime or not?
So my logic was very simple.
Starting from two till end, minus one.
I will try to find just one single number that divides.
And and if I may work to find just one single number that divides in between two to end minus one,
then N is not prime otherwise and is prime.
OK, so let's write pseudocode.
Read an.
I equals to.
While I is less than or it goes to end minus one.
Do.
So what will I do here?
I will try to divide the number by I.
So if.
And as the visible.
By a.
Then.
My number is not prime.
So I can bring here not prime.
And we can end up with.
Get done.
They're done means end up with him.
OK.
Otherwise, what will I do?
I will increase the value if I buy when I close I plus one.
OK, so if the given number is not prime, then I will reach here and my program will be lower.
But what if and this prime then this statement will not be executed and this loop will break and I will
reach here.
So if I reach here, the thing is very clear that and is prime.
So I will print prime and then I will end my program.
So written.
OK, so let's see how it is working with the help of an example.
Let's say, and equals food.
So it did.
And initially I equals two, so I equals to.
And minus one is three then.
Here you are checking is two less than I was two teens.
So the condition is true.
You will come inside the loop, then you will check is full.
There is well by two.
So the condition is true.
You will print not prime.
So I will print not prime.
And then return street men will be executed.
So they're done means and a program.
So my program will end and my output is not prime for any equals four, which is under present.
Correct.
OK.
So let's see one more example.
Let's say the value of end is five.
So did and I equals two.
Okay.
So I equals two and and minus one equals food.
Then it will check the condition.
As to lt goes to fall, the condition is true.
You will come here.
You will come inside the loop.
Then you will check is five neuzil by two?
No.
So this statement will not be executed and you will reach here.
Is there any fiber once the new value is.
And then you will check the condition again.
So Estill, less than or to forward.
So the condition is true.
You will come here is five Neuzil by three.
No.
The condition is false.
This statement will not be executed and you will reach here and give them Radio five Beban to the new
radio fi is for.
Then you will check the condition again is for less than articles two, for the condition is true.
You will come inside the loop.
Then you will check.
Is five divisible by four?
No.
So this statement will not be executed.
You will increase the value if I buy one.
So a new value if I is five.
Then you will check again is five less than articles to four.
So is five less than not to four?
No.
The condition is false.
And this loop will be broken.
We will break this loop.
And then you will reach here.
Print prime.
OK.
So I will print prime.
And then redundantly then means Andu program.
So my output is prime.
Which is hundred percent correct.
For unequals equals five.
So in pseudocode, the instructions are executed.
Line by line, from top to bottom.
OK, so instructions are executed line by line, from top to bottom.
So it does revise how this is working.
Guess what it does surveys where they have done so.
The problem statement was given in.
We have to check whether it is prime or not.
So our logic was very simple.
Starting from two till and minus one.
My aim is to just find one single number that divides and.
If I'm able to find that number, then the number is not Brem.
Otherwise the number is frame.
So I read and I equals to 10.
I is less than or equal to and minus one because we have to go deal and minus one.
You can also right here I Listin and Mutassim.
OK, so I left to N minus one or I left it in the boathouse him.
So if this condition is true what will you do.
You will try to divide the given number.
By I and if I divides in the new will print, not prime.
And you can return return means end of program.
And if this condition is followed, then you will reach here and you will increase the value if I buy
one.
And then you will again come here again.
Check the condition again.
Check if anybody is ill by I.
If this condition is true na prime return.
If this condition is false and gives them a low if I buy one.
So this will keep going on.
Okay.
And if I had each year, that means it it the statement has not been executed.
That means given number is blank.
So I will print crime and written letters and a program.
OK, so let's solve problem number two.
Problem to.
Fined.
Largest off.
And numbers.
If I remember carefully, we have covered this caution and flowcharts.
So what was our logic?
I told you for rating and numbers, I don't know, the value of an elephant will be given by user.
So for rating and numbers, I need a loop.
And each time this loop is earning, what will I do?
I will do the number and I will compare this number with the largest.
And if this number is good, then loudest I will upgrade the value of largest.
And when this loop will end, I will print not just.
OK, so let us.
The so called.
Read an.
I was when.
Largest.
It was minus infinity.
While.
I is less than or equal to N because we have to read in numbers.
So this loop must run and times.
So while I had less than I was doing, I have to read a number, so read.
No.
Compare this number with largest.
So if this number is good, largest.
Then I read the value of largest, largest equals name.
OK.
And then you will increase the value of five by one.
So I equals a plus one.
And Vandersloot will and you will bend largest.
Done, done.
OK, so let us take one example to understand disorder called SUPPOSE.
And it was three.
And I will leave two numbers, three, seven and five.
OK.
So the first step I read and I equals one.
So I equals one.
Logistic equals minus infinity.
OK, so largest.
Equals minus infinity.
Is one less than goes to three?
So the condition is true.
You will come inside the loop.
Then you have to read.
No, I will read three.
Then you will compare tea with the largest.
So is triggered then minus infinity.
Yes.
You will appreciate the value of largest.
So largest.
Equals three.
Then you will increase the value of I buy one.
So the new value of AI is.
Two and then.
They will check the condition again.
So is too late and it goes to three.
So the condition is again through, you will come inside the loop.
Read, no.
This time I will read seven.
OK?
And then you have to compare this number with the largest.
So is it seven good then three.
Yes, the condition is true.
You know, the value of largest so largest equals the number that you have read.
That is seven.
And then you will increase the value of five by one to the new value if I is three.
Then you will check the condition again.
Is still less than one, two, three.
So the condition is again.
You will come inside the loop.
Richard No.
OK.
So this time I will read five.
Compare this number with largest, so is five Gurdon's seven.
No, the condition is false.
And this statement will not be executed.
You will come here.
You will likely come here and give the rally if I buy one.
So then you rally.
If I is fooled.
Then you will check the condition again.
So is for less than I was.
Two three is for less than I was.
Two, three.
No.
The condition is false.
And this loop.
We'll break.
I will come outside of this loop.
I will reach you.
Brind largest.
OK.
So the largest is it goes to seven.
So I will print seven and then return.
That is.
And a program.
So my output is seven which is a hundred percent.
Correct.
Four and equals three.
And the values are two.
Seven five.
OK, so let's revise what we have done.
So the problem was I would define largest of any numbers.
And I told you for reading and numbers, I need to loop.
So this is my initial invasion and this is my condition and this is absolute.
Condition.
Initialization.
And this is update.
So with the help of these three.
My loop will run and thanks.
And each time this loop is ending, I am reading a number and I'm comparing this number with the largest.
And if this number is good, the largest, then I'm updating the value of largest.
Simple.
And after we have read and numbers, this loop will break.
We will come out of this loop and I will print now just.
And then I will finish my program.
Simple.