Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:01,540
What is going on, guys?
2
00:00:01,560 --> 00:00:11,520
And welcome back to another exercising our programming or C C programming course, any of these exercises,
3
00:00:11,520 --> 00:00:20,820
what you are requested to do is to find the difference between the sum of all even numbers of all even
4
00:00:20,820 --> 00:00:28,230
digits as they are and the sum of all odd digits in a given number.
5
00:00:28,260 --> 00:00:35,970
So what we are going to do is to write a function that receives, receives, let's say, receives some
6
00:00:36,120 --> 00:00:39,570
number and the function is going to do the following.
7
00:00:39,960 --> 00:00:41,880
The function is going to find it.
8
00:00:41,890 --> 00:00:48,000
Say that Ngong was, I don't know, seven thousand four hundred and fifty two.
9
00:00:48,750 --> 00:00:52,860
And the song, the function to program.
10
00:00:52,860 --> 00:00:54,780
We haven't covered a function yet.
11
00:00:54,930 --> 00:00:57,510
In the next section I think we are going to talk about it.
12
00:00:57,960 --> 00:01:02,700
They are this program is going to do something very, very simple.
13
00:01:03,060 --> 00:01:12,900
We are going to calculate the sum of all even our digits so we get even digits some equals to simply
14
00:01:12,900 --> 00:01:15,090
four plus two, which is six.
15
00:01:15,300 --> 00:01:15,890
All right.
16
00:01:16,440 --> 00:01:26,520
And then we are going to calculate the order, the digits sum, which in this case is simply seven plus
17
00:01:26,520 --> 00:01:29,430
five, which is a total of 12.
18
00:01:30,210 --> 00:01:41,310
And once we found out the even digits in the digits, we are going to print the even digits sum minus
19
00:01:41,580 --> 00:01:43,320
the odd digits.
20
00:01:44,530 --> 00:01:49,230
So that's basically all that we have to do in this program.
21
00:01:50,220 --> 00:01:54,920
So with that being said, let's dive right away into coding.
22
00:01:55,650 --> 00:02:04,380
So the first question that you should have is how basically you can find and calculate the digit of
23
00:02:04,380 --> 00:02:09,690
every basically calculate and take into account the value of every digit.
24
00:02:10,470 --> 00:02:16,560
So for that list, first of all, create the additional variable and Colignan and read these num from
25
00:02:16,560 --> 00:02:17,110
the user.
26
00:02:17,130 --> 00:02:21,450
So answer Anom with this value and store it inside now.
27
00:02:21,700 --> 00:02:25,140
OK, so that percentage is storing it inside of numbers.
28
00:02:25,950 --> 00:02:30,050
Once you are done with these borith, let's simply think about.
29
00:02:30,060 --> 00:02:35,440
So we need to sum the even digits and we also need to sum the odd digits.
30
00:02:36,030 --> 00:02:43,980
So one way to do so is to create additional variable and call it, let's say even some equals to zero
31
00:02:44,370 --> 00:02:47,530
and all the sum equals to zero.
32
00:02:48,330 --> 00:02:51,880
So that's how we start solving this exercise.
33
00:02:52,710 --> 00:03:02,190
And now what do we have to do is simply start each rating over our given num in basically every time
34
00:03:02,190 --> 00:03:07,260
on every iteration to take the rightmost digit into the sum.
35
00:03:07,680 --> 00:03:13,590
So how it will look like let's first of all create or better say we don't need to create anything here.
36
00:03:13,950 --> 00:03:17,580
So let's say as long as NUM is greater than.
37
00:03:17,580 --> 00:03:19,290
Than what than zero.
38
00:03:19,410 --> 00:03:19,860
Right.
39
00:03:20,080 --> 00:03:22,770
As long as it has at least one digit.
40
00:03:25,920 --> 00:03:26,250
Yeah.
41
00:03:26,250 --> 00:03:27,750
Which is not zero of course.
42
00:03:28,110 --> 00:03:38,490
Then in these case we are going to do is what you ask the following question if ok if let's it or take
43
00:03:38,490 --> 00:03:45,600
it like this also creates additional variable, let's create a digit or current digit.
44
00:03:46,020 --> 00:03:49,890
OK, so if current digit.
45
00:03:50,250 --> 00:03:52,020
OK, what is current digit.
46
00:03:52,020 --> 00:03:52,860
Let's define it.
47
00:03:52,860 --> 00:03:56,490
So current digit equals two nom more Lutin.
48
00:03:56,730 --> 00:04:02,430
OK, so it simply will give you the rightmost digit of num.
49
00:04:03,060 --> 00:04:03,580
All right.
50
00:04:03,630 --> 00:04:10,110
So if we have like seven, four or five to these current digit will be two, OK, because we try to
51
00:04:10,110 --> 00:04:13,780
divide it by ten and that's the remainder which is left, which is two.
52
00:04:14,130 --> 00:04:22,680
So if current digit divided modulo two equals three zero, then it means the current digit current digit
53
00:04:23,460 --> 00:04:24,570
is even.
54
00:04:25,440 --> 00:04:33,630
So in this case, what we should do is simply use even some equals to the previous, even some plus
55
00:04:33,780 --> 00:04:36,930
plus one plus the current digit.
56
00:04:37,410 --> 00:04:38,100
Exactly.
57
00:04:39,210 --> 00:04:49,270
Else, if that's not the case, meaning that current digit is odd, that in this case we have odd some
58
00:04:49,350 --> 00:04:53,820
equals to the previous odd some lost current digit.
59
00:04:54,450 --> 00:04:55,530
So that's OK.
60
00:04:55,560 --> 00:04:57,720
So let's hope that's clear.
61
00:04:57,750 --> 00:04:59,670
So let's just remove this and.
62
00:05:00,660 --> 00:05:08,730
The appropriate signs while sequels to this one, OK, so taking even some of the previous value and
63
00:05:08,730 --> 00:05:14,160
adding to the current Egypt or taking the old songs and adding to the current Egypt.
64
00:05:14,820 --> 00:05:18,440
So basically that's how the for loop these while loop looks like.
65
00:05:18,780 --> 00:05:27,440
And one thing that we still haven't talked about and we didn't add, we haven't added the last line.
66
00:05:28,020 --> 00:05:29,270
Think about it for a second.
67
00:05:29,280 --> 00:05:32,160
What's missing here in the body of this loop?
68
00:05:33,720 --> 00:05:38,190
Basically, this loop is for now kind of infinite loop.
69
00:05:38,410 --> 00:05:45,150
We simply take no, we get the rightmost Egypt, which is still in the next iteration, we will still
70
00:05:45,150 --> 00:05:49,590
get two and and so on and so forth, will always get the right moves.
71
00:05:49,620 --> 00:05:54,850
Egypt is still because now will forever remain greater than zero.
72
00:05:55,290 --> 00:06:02,040
So what we have to do is that once we have taken into account these rightmost Egypt, we should simply
73
00:06:02,040 --> 00:06:05,790
change them from this value to seven, four or five.
74
00:06:05,940 --> 00:06:06,270
Right.
75
00:06:06,270 --> 00:06:09,730
Because we don't need any more of these kind of Egypt.
76
00:06:10,440 --> 00:06:11,620
So how do you do it?
77
00:06:11,640 --> 00:06:16,210
You simply say not goes to the previous number divided by 10.
78
00:06:16,850 --> 00:06:22,200
OK, so when you divide it by 10, you will simply get seven, four or five and that's it.
79
00:06:22,200 --> 00:06:23,730
And that's how you continue working.
80
00:06:23,980 --> 00:06:29,040
Then you are simply working with seven, four, five and you just get the rightmost digit, which is
81
00:06:29,040 --> 00:06:31,800
five, and then you get the right digit, which is four.
82
00:06:32,130 --> 00:06:37,860
And right afterwards you get the right most digit, which is seven, and the final result is going to
83
00:06:37,860 --> 00:06:38,490
be zero.
84
00:06:38,490 --> 00:06:41,430
And this condition is going to be false.
85
00:06:41,430 --> 00:06:45,600
And basically you'll be out of these while loop.
86
00:06:46,650 --> 00:06:50,370
So finally, what you will have to do is just print.
87
00:06:50,470 --> 00:06:55,020
OK, so printf who what do you have to print?
88
00:06:55,020 --> 00:07:09,100
Even aged some minus the odd digit sum equals equals to want to present the D backslash.
89
00:07:09,540 --> 00:07:14,370
And it will be like even some minus odd some.
90
00:07:14,810 --> 00:07:19,590
OK, so that's what our program is all about.
91
00:07:20,460 --> 00:07:24,180
And now let's build and run it to see that everything works as expected.
92
00:07:24,180 --> 00:07:25,110
So international.
93
00:07:25,110 --> 00:07:29,700
Let's go with it like one three, five, eight and six.
94
00:07:30,270 --> 00:07:38,560
So we know that we have the even will be 14 minus nine which should give us even digits, minus all
95
00:07:38,580 --> 00:07:40,980
digits, a total of five.
96
00:07:40,990 --> 00:07:43,340
So everything seems to be working correctly.
97
00:07:43,350 --> 00:07:45,680
Let's go like six, five, four.
98
00:07:45,840 --> 00:07:47,940
It should give us five once again.
99
00:07:47,970 --> 00:07:48,540
Awesome.
100
00:07:49,500 --> 00:07:52,530
So you guys, this is it for this video.
101
00:07:52,540 --> 00:07:53,910
I hope you enjoyed it.
102
00:07:54,330 --> 00:07:59,070
Please let me know if you still have any questions, and I'll see you next time.
9584
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.