Hey, guys, what's up?
So today we are solving one more interesting problem.
So the problem is that I had to function.
To generate.
All prime numbers.
From to do.
And OK.
So we have to write a function to generate all the prime numbers from to do and and will be given by
user.
So, for example, if the value of and is, then my output should be two, three, five, seven.
OK.
So these are the prime numbers from Tautou and.
Similarly, if my input is, let's say five, so men are butchered, we do three and five.
OK, so if the value of a..
Fifteen, my output should be two, three, five, seven, eleven and thirteen.
OK, so we have to print all the prime numbers from to do an.
Now, how against all this problem?
So the problem is very easy.
What we have to do.
I will run a loop from I equals two.
So I will in a loop from two till.
And and each time this loop is running, what I will do, I will check for each number.
If that number is prime, I will check.
I will check for each number if the number is prime, see out prime otherwise and don't print.
OK, so what do we do?
We will run a loop starting from two till and.
And for each number I will check if this number is prime.
You can print this number.
OK.
So, for example, I am checking for three.
So if trace prime print three, I will check for four.
So is four prime.
No.
So don't print it.
I will check for five.
Is five prime.
Yes.
Five is prime.
So print five.
And how to check whether a number is prime or not.
We have seen this in the last video.
OK, so the last video was this only how to check whether your number is primeur not.
So that's right.
Cornford.
OK, so let's name it.
Gender frame.
Not CBP.
OK, so we have to generate the numbers from two to end, sort of drastic.
What is the value of an C in an.
And what do we do?
We will write a function and gender frame, so generate.
So Janet frame function will take and as input.
OK.
So now we have to right generate brain function.
So does Jonette brain function will print all the prime numbers from to do and.
Okay, so what, this GeoNet function will return.
So the answer is it will not return anything.
It will just print all these numbers so that it can type is void.
So void.
Generate frame.
It will take the videophone from today.
We have to print so it will take a. input.
Now, what do we do?
Starting from do Bill and I will check if the number is prime.
Print.
So I'm going to check if this number.
So I will write is prime function.
So if this number.
That this current number, which is a.
So if this number is prime, we have to print this number.
So see old print.
This number.
OK, so now our task is to implement this is frame function.
Now, in the last two plus, we have already implemented this function.
So I'm just copying and pasting it here.
Now, where should I pasted below intervene or after word gendered or before word gendered?
So main function is calling gender to prime.
So generate prem was defined above.
Now gendered brain function is calling a sperm function.
So a sperm function should be defined above.
Now I think everything is right.
So let's test our program.
Led to the release of and is then.
So two, three, five and seven are the prime numbers from two to 10.
Let's say the elephant is handled.
So these many are prime numbers from two two hundred.
Now, let's test it one last time.
Let's say they're really oftenest 13.
So two, three five seven eleven.
Entertain the.
Are the prime numbers from two to 13.
So what is happening here?
This main function is calling gendered brain function.
Hence this gendered brain function will be declared above the main function.
This generate brain function is calling prime function.
So brain function as declared above the gender brain function.
So we can see here our goal becomes reuseable and this is the main advantage of functions.
One more thing.
You can see the code written in the mean has drastically reduced.
Saola code becomes very organized.
OK.
And also, for example, if my code is giving the wrong output, then I can check individual function.
I can check is brain function is working correct or not.
Then I can check.
Is the jonette brain function working, correct or not?
And if both of them are correct, then I can check whether there is an issue in the main.
OK, so other code becomes usable, our court becomes organized and our debugging speed increases again.
It becomes easier to debug.
OK, guys.
So this is it for this video.
If you have any doubt, feel free to ask.
Thank you.