1
00:00:02,830 --> 00:00:04,360
Hey, guys, what's up?

2
00:00:04,870 --> 00:00:07,630
So today we are solving one more interesting problem.

3
00:00:08,190 --> 00:00:10,660
So the problem is that I had to function.

4
00:00:11,940 --> 00:00:12,690
To generate.

5
00:00:15,510 --> 00:00:16,820
All prime numbers.

6
00:00:20,630 --> 00:00:22,920
From to do.

7
00:00:23,420 --> 00:00:24,750
And OK.

8
00:00:25,220 --> 00:00:32,870
So we have to write a function to generate all the prime numbers from to do and and will be given by

9
00:00:33,140 --> 00:00:33,550
user.

10
00:00:34,550 --> 00:00:42,470
So, for example, if the value of and is, then my output should be two, three, five, seven.

11
00:00:42,860 --> 00:00:43,060
OK.

12
00:00:43,160 --> 00:00:46,130
So these are the prime numbers from Tautou and.

13
00:00:47,410 --> 00:00:54,460
Similarly, if my input is, let's say five, so men are butchered, we do three and five.

14
00:00:55,560 --> 00:00:57,020
OK, so if the value of a..

15
00:00:57,080 --> 00:01:03,950
Fifteen, my output should be two, three, five, seven, eleven and thirteen.

16
00:01:04,440 --> 00:01:09,980
OK, so we have to print all the prime numbers from to do an.

17
00:01:11,380 --> 00:01:13,000
Now, how against all this problem?

18
00:01:13,950 --> 00:01:15,250
So the problem is very easy.

19
00:01:16,060 --> 00:01:16,840
What we have to do.

20
00:01:16,930 --> 00:01:19,500
I will run a loop from I equals two.

21
00:01:20,230 --> 00:01:23,170
So I will in a loop from two till.

22
00:01:24,230 --> 00:01:29,950
And and each time this loop is running, what I will do, I will check for each number.

23
00:01:30,420 --> 00:01:34,140
If that number is prime, I will check.

24
00:01:35,880 --> 00:01:42,150
I will check for each number if the number is prime, see out prime otherwise and don't print.

25
00:01:45,120 --> 00:01:48,040
OK, so what do we do?

26
00:01:48,190 --> 00:01:52,830
We will run a loop starting from two till and.

27
00:01:53,620 --> 00:01:58,000
And for each number I will check if this number is prime.

28
00:01:58,300 --> 00:01:59,590
You can print this number.

29
00:02:00,390 --> 00:02:00,660
OK.

30
00:02:00,880 --> 00:02:02,590
So, for example, I am checking for three.

31
00:02:02,650 --> 00:02:06,340
So if trace prime print three, I will check for four.

32
00:02:06,700 --> 00:02:07,960
So is four prime.

33
00:02:07,990 --> 00:02:08,380
No.

34
00:02:08,500 --> 00:02:09,400
So don't print it.

35
00:02:10,000 --> 00:02:11,140
I will check for five.

36
00:02:11,290 --> 00:02:12,120
Is five prime.

37
00:02:12,310 --> 00:02:12,590
Yes.

38
00:02:12,610 --> 00:02:13,540
Five is prime.

39
00:02:13,570 --> 00:02:14,560
So print five.

40
00:02:15,670 --> 00:02:18,430
And how to check whether a number is prime or not.

41
00:02:18,850 --> 00:02:20,710
We have seen this in the last video.

42
00:02:21,710 --> 00:02:27,280
OK, so the last video was this only how to check whether your number is primeur not.

43
00:02:29,860 --> 00:02:30,550
So that's right.

44
00:02:30,610 --> 00:02:31,170
Cornford.

45
00:02:38,160 --> 00:02:39,210
OK, so let's name it.

46
00:02:41,460 --> 00:02:42,340
Gender frame.

47
00:02:44,900 --> 00:02:46,100
Not CBP.

48
00:03:05,610 --> 00:03:10,010
OK, so we have to generate the numbers from two to end, sort of drastic.

49
00:03:10,500 --> 00:03:15,240
What is the value of an C in an.

50
00:03:18,670 --> 00:03:19,630
And what do we do?

51
00:03:19,690 --> 00:03:23,020
We will write a function and gender frame, so generate.

52
00:03:26,540 --> 00:03:31,370
So Janet frame function will take and as input.

53
00:03:33,590 --> 00:03:33,830
OK.

54
00:03:34,790 --> 00:03:38,090
So now we have to right generate brain function.

55
00:03:39,350 --> 00:03:43,850
So does Jonette brain function will print all the prime numbers from to do and.

56
00:03:44,800 --> 00:03:47,210
Okay, so what, this GeoNet function will return.

57
00:03:47,510 --> 00:03:49,700
So the answer is it will not return anything.

58
00:03:49,970 --> 00:03:54,110
It will just print all these numbers so that it can type is void.

59
00:03:54,980 --> 00:03:55,580
So void.

60
00:03:57,810 --> 00:04:00,210
Generate frame.

61
00:04:00,900 --> 00:04:05,020
It will take the videophone from today.

62
00:04:05,310 --> 00:04:07,550
We have to print so it will take a. input.

63
00:04:09,060 --> 00:04:09,860
Now, what do we do?

64
00:04:10,800 --> 00:04:15,150
Starting from do Bill and I will check if the number is prime.

65
00:04:15,260 --> 00:04:15,630
Print.

66
00:04:20,960 --> 00:04:24,410
So I'm going to check if this number.

67
00:04:24,800 --> 00:04:26,420
So I will write is prime function.

68
00:04:27,770 --> 00:04:30,020
So if this number.

69
00:04:30,140 --> 00:04:31,810
That this current number, which is a.

70
00:04:32,180 --> 00:04:36,710
So if this number is prime, we have to print this number.

71
00:04:37,040 --> 00:04:38,860
So see old print.

72
00:04:39,080 --> 00:04:39,980
This number.

73
00:04:42,900 --> 00:04:48,330
OK, so now our task is to implement this is frame function.

74
00:04:50,750 --> 00:04:53,820
Now, in the last two plus, we have already implemented this function.

75
00:04:54,380 --> 00:04:57,380
So I'm just copying and pasting it here.

76
00:04:57,770 --> 00:05:04,100
Now, where should I pasted below intervene or after word gendered or before word gendered?

77
00:05:05,480 --> 00:05:08,320
So main function is calling gender to prime.

78
00:05:08,480 --> 00:05:11,060
So generate prem was defined above.

79
00:05:11,420 --> 00:05:14,240
Now gendered brain function is calling a sperm function.

80
00:05:14,600 --> 00:05:17,900
So a sperm function should be defined above.

81
00:05:19,940 --> 00:05:22,100
Now I think everything is right.

82
00:05:23,810 --> 00:05:25,520
So let's test our program.

83
00:05:33,890 --> 00:05:36,220
Led to the release of and is then.

84
00:05:38,320 --> 00:05:42,090
So two, three, five and seven are the prime numbers from two to 10.

85
00:05:46,220 --> 00:05:47,790
Let's say the elephant is handled.

86
00:05:49,620 --> 00:05:52,910
So these many are prime numbers from two two hundred.

87
00:05:53,660 --> 00:05:55,580
Now, let's test it one last time.

88
00:05:56,490 --> 00:05:58,070
Let's say they're really oftenest 13.

89
00:05:59,490 --> 00:06:01,370
So two, three five seven eleven.

90
00:06:01,370 --> 00:06:01,920
Entertain the.

91
00:06:02,150 --> 00:06:05,620
Are the prime numbers from two to 13.

92
00:06:07,100 --> 00:06:08,180
So what is happening here?

93
00:06:08,300 --> 00:06:11,450
This main function is calling gendered brain function.

94
00:06:11,840 --> 00:06:16,010
Hence this gendered brain function will be declared above the main function.

95
00:06:16,400 --> 00:06:19,220
This generate brain function is calling prime function.

96
00:06:19,500 --> 00:06:23,750
So brain function as declared above the gender brain function.

97
00:06:24,530 --> 00:06:32,120
So we can see here our goal becomes reuseable and this is the main advantage of functions.

98
00:06:32,840 --> 00:06:33,620
One more thing.

99
00:06:34,040 --> 00:06:38,360
You can see the code written in the mean has drastically reduced.

100
00:06:38,890 --> 00:06:41,270
Saola code becomes very organized.

101
00:06:42,970 --> 00:06:43,300
OK.

102
00:06:44,580 --> 00:06:50,940
And also, for example, if my code is giving the wrong output, then I can check individual function.

103
00:06:51,270 --> 00:06:54,400
I can check is brain function is working correct or not.

104
00:06:55,050 --> 00:06:55,950
Then I can check.

105
00:06:56,310 --> 00:06:58,920
Is the jonette brain function working, correct or not?

106
00:06:59,550 --> 00:07:03,930
And if both of them are correct, then I can check whether there is an issue in the main.

107
00:07:04,850 --> 00:07:13,070
OK, so other code becomes usable, our court becomes organized and our debugging speed increases again.

108
00:07:13,200 --> 00:07:14,820
It becomes easier to debug.

109
00:07:15,940 --> 00:07:16,480
OK, guys.

110
00:07:16,600 --> 00:07:17,870
So this is it for this video.

111
00:07:17,980 --> 00:07:19,840
If you have any doubt, feel free to ask.

112
00:07:20,560 --> 00:07:21,040
Thank you.
