1
00:00:01,390 --> 00:00:03,010
Hey, guys, what's up?

2
00:00:03,490 --> 00:00:06,580
So today we are going to solve one more interesting problem.

3
00:00:07,030 --> 00:00:18,490
So the problem statement is given in it was it will give us and and we have to find some of even numbers.

4
00:00:22,160 --> 00:00:29,180
From one to and so you it will give us the value of N.

5
00:00:29,240 --> 00:00:36,290
And we have to find the sum of even numbers starting from one billion, for example, and equals five.

6
00:00:36,440 --> 00:00:44,330
So even numbers are two plus for some output should be six for enclose five mild butchered B6.

7
00:00:45,020 --> 00:00:47,220
Similarly to the value of N is eight.

8
00:00:47,720 --> 00:00:55,420
So output should be two plus four plus six plus eight, which is 20.

9
00:00:55,520 --> 00:00:57,380
So output should be 20.

10
00:00:58,700 --> 00:00:58,940
OK.

11
00:00:59,510 --> 00:01:02,750
And similarly, let's say the value of an is three.

12
00:01:03,170 --> 00:01:05,300
So now it will be to.

13
00:01:06,560 --> 00:01:13,170
OK, so if you remember, we have already solved this problem in flowcharts, in pseudocode.

14
00:01:13,940 --> 00:01:16,130
But today we will be writing the actual code.

15
00:01:17,220 --> 00:01:20,360
Okay, so how we can solve this problem.

16
00:01:22,250 --> 00:01:27,900
So first of all, what I will do, I will take no scene and as in.

17
00:01:29,180 --> 00:01:29,420
OK.

18
00:01:29,870 --> 00:01:34,100
So for finding the sum what I need, I need a loop.

19
00:01:34,190 --> 00:01:35,300
I need a variable.

20
00:01:35,660 --> 00:01:37,230
Let's call it some.

21
00:01:38,300 --> 00:01:44,620
And we will add the values to the some of the variable some.

22
00:01:45,590 --> 00:01:49,250
So I need a loop and this loop will start from two.

23
00:01:49,730 --> 00:01:50,890
So I need a loop.

24
00:01:51,980 --> 00:01:56,380
And this loop will start from two three.

25
00:01:56,750 --> 00:01:59,440
I is less than ordered close to N.

26
00:02:01,280 --> 00:02:05,450
And each time what I will do I will add the value of.

27
00:02:05,840 --> 00:02:08,000
I do my variable some.

28
00:02:09,510 --> 00:02:12,900
And here I equals a plus two.

29
00:02:13,440 --> 00:02:18,240
So why I am incrementing by two, because we have to consider even numbers.

30
00:02:18,630 --> 00:02:20,400
And the first even number is two.

31
00:02:21,420 --> 00:02:22,800
So the first two numbers two.

32
00:02:22,880 --> 00:02:25,650
And that's why I initialised I equals two.

33
00:02:26,040 --> 00:02:29,430
And since we have to go see this, we have to consider only even numbers.

34
00:02:30,090 --> 00:02:32,730
So I will increase the value of Ibai to.

35
00:02:33,880 --> 00:02:40,480
OK, so after running this look, my variable sum will be containing my answer and I will print some

36
00:02:40,480 --> 00:02:41,920
here, see out some.

37
00:02:42,430 --> 00:02:44,260
So this is all that we have to do.

38
00:02:44,980 --> 00:02:46,650
So first, let us write code.

39
00:02:50,490 --> 00:02:52,490
So let us name this file as.

40
00:02:56,120 --> 00:03:00,560
Some of even Nazi BP.

41
00:03:18,200 --> 00:03:26,210
Now, what I have to do, first of all, I will take a variable in and I will take and as input from

42
00:03:26,210 --> 00:03:27,210
the user.

43
00:03:29,210 --> 00:03:33,230
So I need a variable sum which will hold my answer.

44
00:03:34,550 --> 00:03:42,140
So I need a loop which will start from two do, because two is the first even number.

45
00:03:42,650 --> 00:03:48,350
And this loop will run while I is less than ordered close to end.

46
00:03:49,100 --> 00:03:56,210
And each time this loop is learning what I have to do, I have to add the current even number to my

47
00:03:56,210 --> 00:03:57,320
variable sum.

48
00:03:57,380 --> 00:04:02,480
So some equals some plus I and I have to go to next even number.

49
00:04:03,080 --> 00:04:08,510
So next year when number can be obtained by adding two to my current given number.

50
00:04:09,890 --> 00:04:11,270
So this is all that we have to do.

51
00:04:11,870 --> 00:04:16,310
And then I will print some which is holding my answer.

52
00:04:17,300 --> 00:04:17,470
OK.

53
00:04:17,540 --> 00:04:19,490
So this is all that we have to do.

54
00:04:20,510 --> 00:04:22,210
What the output will be wrong.

55
00:04:23,550 --> 00:04:23,780
Why?

56
00:04:24,260 --> 00:04:24,790
Let's see.

57
00:04:29,440 --> 00:04:31,370
So let's say the value of any is three.

58
00:04:31,450 --> 00:04:36,970
So our purchase, we do so Oddworld is coming out to be a very strange number.

59
00:04:38,190 --> 00:04:38,370
OK.

60
00:04:38,530 --> 00:04:39,190
So let's see.

61
00:04:39,550 --> 00:04:43,820
Let's bring it on our program and let's see what went wrong.

62
00:04:48,060 --> 00:04:50,730
So the value of and is three.

63
00:04:51,560 --> 00:04:51,750
OK.

64
00:04:51,930 --> 00:04:53,640
So the first event number is two.

65
00:04:54,090 --> 00:04:59,220
So I equals two ISBN initialised way to him because two is the first event number.

66
00:04:59,790 --> 00:05:04,380
And this loop will run till I is less than articles two.

67
00:05:04,800 --> 00:05:09,520
And so if I start watching, this condition is two less than articles two three.

68
00:05:10,590 --> 00:05:12,700
So is two less than articles today.

69
00:05:12,750 --> 00:05:13,770
So the condition is true.

70
00:05:13,860 --> 00:05:15,340
I will go inside the loop.

71
00:05:15,930 --> 00:05:19,920
So I will add the current even number for my variable sum.

72
00:05:20,790 --> 00:05:29,100
So some equals current value of some plus current even number, which is to.

73
00:05:30,250 --> 00:05:34,900
But what happened here is what is the value of getting some?

74
00:05:36,730 --> 00:05:41,380
So I don't know if you remember when we had it, when we arrived in sum.

75
00:05:43,150 --> 00:05:51,280
So what will happen this some variable will be given for bites of memory and the name of these four

76
00:05:51,280 --> 00:05:52,150
bites out of some.

77
00:05:53,600 --> 00:05:55,240
OK, so we are not right.

78
00:05:55,330 --> 00:05:56,740
So we are not writing anything here.

79
00:05:56,800 --> 00:06:01,030
So by default, there is a combination of zero one zero zero one zero and so on.

80
00:06:01,600 --> 00:06:03,730
So this really is called garbage value.

81
00:06:06,450 --> 00:06:07,280
Garbage value.

82
00:06:07,960 --> 00:06:08,650
So is my son.

83
00:06:08,650 --> 00:06:11,140
Variable is containing garbage value.

84
00:06:12,040 --> 00:06:13,840
And it should have contain zero.

85
00:06:15,490 --> 00:06:16,300
So let me show you.

86
00:06:17,470 --> 00:06:18,550
So here I am.

87
00:06:18,550 --> 00:06:20,440
Printing led to the value of some.

88
00:06:21,130 --> 00:06:22,600
So I am printing some here.

89
00:06:27,860 --> 00:06:29,030
And it's commented out.

90
00:06:32,680 --> 00:06:34,510
Led to the value of and these two.

91
00:06:35,330 --> 00:06:40,830
So this is the valley of some Myozyme is containing any random number.

92
00:06:41,180 --> 00:06:45,440
And this number is called garbage because it is of no use to us.

93
00:06:46,690 --> 00:06:47,770
So what we should do?

94
00:06:50,240 --> 00:06:54,600
We have created the variable sum we have to initialize, initialize it with zero.

95
00:06:55,440 --> 00:06:58,500
OK, so initially my sum is zero.

96
00:06:59,790 --> 00:07:01,590
And now our code is hundred percent.

97
00:07:01,680 --> 00:07:02,100
Correct.

98
00:07:02,190 --> 00:07:02,810
So let's see.

99
00:07:05,820 --> 00:07:09,590
So let's turn our program low to the value of amnesty.

100
00:07:09,630 --> 00:07:12,390
So our budget we do, which is hundred percent correct.

101
00:07:14,760 --> 00:07:18,550
Four and equals five, six, four, eight, 20.

102
00:07:18,990 --> 00:07:20,460
So five and eight.

103
00:07:20,640 --> 00:07:24,470
OK, so friend equals five.

104
00:07:24,830 --> 00:07:26,130
My output is six.

105
00:07:28,990 --> 00:07:31,920
And for any equals, eight wild four days.

106
00:07:32,140 --> 00:07:33,410
Don't be so recorders.

107
00:07:33,460 --> 00:07:35,200
Hundred percent correct.

108
00:07:35,620 --> 00:07:37,840
But let's see how it works.

109
00:07:40,220 --> 00:07:41,900
So our goal is very simple.

110
00:07:43,360 --> 00:07:49,820
And I'm taking a variable sum, which is initialized to zero because initially the sum will be zero.

111
00:07:50,420 --> 00:07:52,840
And my first event number is two.

112
00:07:53,720 --> 00:08:04,160
And this loop is will be running while I is less than or equal to N and each time I will add the current

113
00:08:04,160 --> 00:08:04,550
sum.

114
00:08:05,420 --> 00:08:06,560
The current even number.

115
00:08:06,590 --> 00:08:11,060
So I is containing current even number.

116
00:08:12,320 --> 00:08:18,530
I is containing currently one number and I am adding that current event number to my variable sum.

117
00:08:20,060 --> 00:08:20,240
OK.

118
00:08:20,390 --> 00:08:22,380
Now I have to go to next event number.

119
00:08:22,940 --> 00:08:28,340
So for going to next event number, I will add two to my current division number.

120
00:08:29,150 --> 00:08:36,010
And finally, when this loop will terminate, my answer will be stored in my variable sum.

121
00:08:36,140 --> 00:08:38,030
So this is the whole code.

122
00:08:39,230 --> 00:08:42,030
Now, let us test our program for any quiz.

123
00:08:42,440 --> 00:08:43,220
Let's say five.

124
00:08:44,780 --> 00:08:46,760
So initially, the value of PHI is two.

125
00:08:47,360 --> 00:08:49,880
And initially my sum is zero.

126
00:08:50,600 --> 00:08:51,620
So check the condition.

127
00:08:51,980 --> 00:08:55,280
So is to list then or close to five.

128
00:08:55,340 --> 00:08:58,160
Yes, the condition is true and I do the same.

129
00:08:58,610 --> 00:09:02,840
So sum, it was all value of sum, which is zero plus two.

130
00:09:03,470 --> 00:09:06,670
So some equations do now increase the value of Highway two.

131
00:09:07,280 --> 00:09:10,360
So a new value of EI is for this next to number.

132
00:09:11,030 --> 00:09:12,390
And my sum is two.

133
00:09:13,160 --> 00:09:14,540
So check the condition.

134
00:09:15,530 --> 00:09:17,610
So is it for less than articles two?

135
00:09:17,660 --> 00:09:20,690
Five is food listin or close to five.

136
00:09:21,080 --> 00:09:22,370
Yes, the condition is true.

137
00:09:23,180 --> 00:09:24,840
So sum it goes oil away.

138
00:09:24,860 --> 00:09:30,110
Leave some which is two plus I, which is for the sum equals six.

139
00:09:30,950 --> 00:09:34,400
Now inglese the value of EI noticeable next to a number.

140
00:09:34,430 --> 00:09:38,750
So I equals six and my sum is containing six year.

141
00:09:42,240 --> 00:09:43,780
Now, check the condition again.

142
00:09:44,910 --> 00:09:47,970
So is six less than or close to five?

143
00:09:48,940 --> 00:09:49,090
No.

144
00:09:49,400 --> 00:09:53,130
The condition is false, since the condition is false.

145
00:09:53,220 --> 00:09:53,680
I will.

146
00:09:53,760 --> 00:09:59,850
This loop will get terminated and I will reach at this point and I am printing some.

147
00:10:00,360 --> 00:10:07,830
So I am printing six, which is correct answer because two plus four equals six for N equals five.

148
00:10:08,610 --> 00:10:11,640
So this is how our code is working.

149
00:10:12,300 --> 00:10:19,590
So the thing that we have done is called Dryden Diren means you're on your code manually on pen and

150
00:10:19,590 --> 00:10:24,510
paper to see how things are working to get a better understanding of your code.

151
00:10:25,730 --> 00:10:32,420
So what changes can we do here is so we can also write like this?

152
00:10:33,900 --> 00:10:41,290
Instead of writing some, it simply say we can write some blows equals a. they both are the same.

153
00:10:42,210 --> 00:10:48,260
Similarly, instead of writing a class, I pledge to I can write a blessed equals two.

154
00:10:49,530 --> 00:10:51,180
I'll get to the meaning will remain the same.

155
00:10:51,330 --> 00:10:54,450
This is just another way in which we can write.

156
00:10:57,280 --> 00:11:00,680
Now to the value of these five, some outproduce six.

157
00:11:02,310 --> 00:11:15,590
OK, so what I told you, you can write like some it, some place I or some classic close eye.

158
00:11:15,810 --> 00:11:16,980
They both are same.

159
00:11:17,540 --> 00:11:22,470
Similarly I was a plus two or I plus equals two.

160
00:11:22,560 --> 00:11:24,250
They both seem similarly.

161
00:11:24,750 --> 00:11:30,800
I was I you multiply by two or I might reply equals two.

162
00:11:30,880 --> 00:11:31,730
They were without him.

163
00:11:32,480 --> 00:11:39,720
Similarly I equals I two and I they will die same.

164
00:11:39,740 --> 00:11:46,710
Similarly and let's say I equals I multiply by seven so I multiply equals seven.

165
00:11:46,770 --> 00:11:49,070
So do the same.

166
00:11:49,500 --> 00:11:52,770
OK, this is just our way of writing.

167
00:11:53,330 --> 00:11:53,540
Okay.

168
00:11:53,620 --> 00:11:54,810
It doesn't make any difference.

169
00:11:55,110 --> 00:11:57,450
It is just a way of writing.

170
00:11:59,530 --> 00:12:03,580
OK, so the code was pretty simple and easy.

171
00:12:04,450 --> 00:12:05,980
So I hope you understood this problem.

172
00:12:06,010 --> 00:12:09,040
So if you have any doubt, feel free to ask.

173
00:12:09,440 --> 00:12:09,690
OK.

174
00:12:10,270 --> 00:12:12,040
So that is all for this video.

175
00:12:12,220 --> 00:12:12,700
Thank you.
