Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,450 --> 00:00:02,410
Hoo hoo hoo hoo hoo hoo.
2
00:00:02,520 --> 00:00:10,560
Ed. Long exercise in our programming, programming, programming, C programming language.
3
00:00:10,590 --> 00:00:14,960
OK, so let's go another exercise, huh?
4
00:00:15,300 --> 00:00:18,680
So what do we have to do here is to write a program.
5
00:00:18,690 --> 00:00:19,950
What is the program?
6
00:00:19,950 --> 00:00:21,460
What is this program should do?
7
00:00:21,840 --> 00:00:26,400
It's a program that receives three integers, so we should receive three integers.
8
00:00:26,760 --> 00:00:31,890
And based on these three integers, we know that there may be a couple of beers.
9
00:00:31,890 --> 00:00:32,160
Right.
10
00:00:32,170 --> 00:00:38,760
So, for example, our integers are going to be A, B and C, OK, now one and two and three.
11
00:00:39,270 --> 00:00:43,410
Then from A, B and C, we can generate a couple of pairs.
12
00:00:43,650 --> 00:00:50,430
So there may be a pair like A and B, there may be a pair of like B and C and there may be also a player
13
00:00:50,430 --> 00:00:57,270
like A and C, OK, so there are only three pairs that may be generated, three unique pairs from this
14
00:00:57,600 --> 00:00:59,610
sequence of three integers.
15
00:01:00,450 --> 00:01:08,970
And basically what we should do is simply to take each pair and see if we can take either B and divided
16
00:01:08,970 --> 00:01:16,740
by A without a remainder or taking A and dividing it by B without the remainder and do the same process
17
00:01:16,740 --> 00:01:17,880
for these pair.
18
00:01:17,880 --> 00:01:18,750
And also four.
19
00:01:18,750 --> 00:01:19,400
That's better.
20
00:01:19,800 --> 00:01:29,880
And finally, if we could find that each pair contains it, it has at least one value that can be divided
21
00:01:29,880 --> 00:01:32,880
by the other without any remainder.
22
00:01:33,000 --> 00:01:38,100
Then in this case we should simply print something like what was advisable.
23
00:01:38,310 --> 00:01:41,750
OK, otherwise we should print not divisible.
24
00:01:42,330 --> 00:01:49,380
OK, so that's just the simple exercise to practice your knowledge and your skills of using conditions.
25
00:01:49,380 --> 00:01:50,800
Again, just some logic.
26
00:01:51,300 --> 00:01:59,190
So let's start by getting first of all, let's create the variables, read the values from the user
27
00:01:59,190 --> 00:02:04,940
and later on construct our condition so that we'll look something like this.
28
00:02:04,980 --> 00:02:06,840
So let's say No.
29
00:02:06,840 --> 00:02:16,380
One and two and three, OK, or better say let's go with A, B and C showing A, B and C, so int A,
30
00:02:16,380 --> 00:02:25,380
B and C, and in this case we are going to use print F cancer and her and her answer a OK.
31
00:02:25,740 --> 00:02:35,490
And then the user will specify A and we will use an F to read the value to a K to A or basically let's
32
00:02:35,520 --> 00:02:39,490
just use one kind of command to read all of them.
33
00:02:39,490 --> 00:02:44,010
So those kind of percentage will have a three percentage lead once again.
34
00:02:44,010 --> 00:02:52,560
Once again, answer A, B, B and C, OK, that's what the user is going to insert in this line.
35
00:02:52,560 --> 00:03:00,380
We will read all the three integers from the screen and store them inside variables A, B and C, awesome.
36
00:03:00,750 --> 00:03:07,080
So now that we have all of this information, let's start thinking about what should be the condition.
37
00:03:07,650 --> 00:03:09,630
So the condition is constructed.
38
00:03:09,630 --> 00:03:11,850
It's going to be very on condition.
39
00:03:11,970 --> 00:03:15,030
So prepare yourself, maybe grab something to drink.
40
00:03:16,350 --> 00:03:16,700
Yeah.
41
00:03:16,720 --> 00:03:20,130
So the condition is going to do the following thing.
42
00:03:20,550 --> 00:03:25,110
We will check if we can divide B, OK, we'll take all the pairs.
43
00:03:25,110 --> 00:03:25,380
Right.
44
00:03:25,390 --> 00:03:29,310
There are three total of three pairs and we will take for each pair.
45
00:03:29,340 --> 00:03:35,730
We'll test out two conditions if B can be divided by eight without the remainder.
46
00:03:36,030 --> 00:03:42,630
And also if it's not the case, we will check if eight can be divided by B without a remainder.
47
00:03:42,900 --> 00:03:49,780
OK, and we will repeat these process in checking also for the player and for the last pair.
48
00:03:50,490 --> 00:03:59,340
So how it will look like that's first of all, start with a single F f so we know that if A can be divided
49
00:03:59,340 --> 00:04:03,950
by B without a remainder then that's OK.
50
00:04:05,280 --> 00:04:13,170
And if it's not something that is possible, then let's check if we maybe can be divided by a without
51
00:04:13,170 --> 00:04:13,990
a remainder.
52
00:04:14,040 --> 00:04:21,480
So if A can be divided by B without the remainder or beacon divided by A without a remainder, then
53
00:04:21,480 --> 00:04:23,550
we know that these pair will return.
54
00:04:24,120 --> 00:04:25,110
True right.
55
00:04:25,110 --> 00:04:27,220
B, A and B will return true.
56
00:04:27,780 --> 00:04:31,160
So that's not enough to print divisible numbers.
57
00:04:31,470 --> 00:04:35,040
What we have to do is check also the two other pairs.
58
00:04:35,040 --> 00:04:41,040
So we will see and and what will happen in the next pair.
59
00:04:41,040 --> 00:04:51,660
So if B can be divided by C without a remainder in or OK or C can be divided by B without the remainder,
60
00:04:51,660 --> 00:04:57,450
because even if one of them can be divided by the other without a remainder, that's also OK.
61
00:04:58,110 --> 00:04:59,940
And then if that's the case then.
62
00:05:00,000 --> 00:05:07,800
We need to check the third the third pillar, which is if a can be divided by sea without the remainder
63
00:05:08,250 --> 00:05:12,940
or C can be divided by a without a remainder.
64
00:05:13,470 --> 00:05:19,640
So if you can see here, we have two and logical operators.
65
00:05:19,950 --> 00:05:29,490
So if one pair does not or does not happen to satisfy this condition, then the whole result will return
66
00:05:29,730 --> 00:05:31,680
or basically print, not divisive.
67
00:05:32,250 --> 00:05:41,450
But if all of them, all the Paris has at least one value that can be divided by the other value without
68
00:05:41,460 --> 00:05:42,210
a remainder.
69
00:05:42,570 --> 00:05:49,680
And in this case, we will simply print divisive the visible numbers.
70
00:05:49,880 --> 00:05:50,370
All right.
71
00:05:50,380 --> 00:05:53,040
So that's how we are going to do it.
72
00:05:54,010 --> 00:05:59,010
But if at least one of them OK, one of them, OK, that's the first bear.
73
00:05:59,040 --> 00:06:03,810
The comparison for the first bear, this second bear and the third bear.
74
00:06:03,990 --> 00:06:10,710
And in each bear, it's sufficient that at least A, maybe divided by B or be divided by A, they don't
75
00:06:10,710 --> 00:06:13,130
have to both of them be divided by one another.
76
00:06:13,140 --> 00:06:13,420
Right.
77
00:06:13,890 --> 00:06:21,720
So if one parent does not satisfy the condition, then in this case we will use the L's statement and
78
00:06:21,720 --> 00:06:26,520
printf not divisive numbers.
79
00:06:26,940 --> 00:06:29,730
OK, guys, so that's how we do it.
80
00:06:29,740 --> 00:06:31,250
Not divisible numbers.
81
00:06:32,070 --> 00:06:32,750
Awesome.
82
00:06:33,270 --> 00:06:41,580
So the condition maybe not so straightforward from our first glance, but I think that if we take additional
83
00:06:41,580 --> 00:06:48,000
look and try to understand it even further, that's not so, so scary process, is it?
84
00:06:48,820 --> 00:06:51,940
So let's build and run it and let's see what happens.
85
00:06:51,970 --> 00:07:00,250
So answer A, B and C. So we had an example like five, 10 and 20 and these numbers were advisable.
86
00:07:00,250 --> 00:07:02,830
So divisible numbers are awesome.
87
00:07:03,250 --> 00:07:10,870
And let's use another example, like two, four and seven, where we know that two and four are kind
88
00:07:10,870 --> 00:07:11,680
of divisible.
89
00:07:11,860 --> 00:07:13,480
Four, it can be divided by two.
90
00:07:13,780 --> 00:07:16,450
But seven is the odd number here.
91
00:07:16,450 --> 00:07:17,790
And it's kind of problematic.
92
00:07:18,100 --> 00:07:21,130
So let's say not divisible numbers.
93
00:07:21,220 --> 00:07:28,030
OK, so you see that this program seems to be working correctly, but there may be some problem when
94
00:07:28,030 --> 00:07:29,670
doing the following thing.
95
00:07:30,460 --> 00:07:33,760
Let's try to build and run it and let's see what happens.
96
00:07:33,790 --> 00:07:39,070
So let's say we have five, we have 10 and we have zero.
97
00:07:39,880 --> 00:07:48,910
Then in this case, probably we will or our program is going to crash or we will get some very strange
98
00:07:48,910 --> 00:07:55,780
number that a process return not zero like it should if we succeeded, but some other a number and we
99
00:07:55,780 --> 00:08:00,690
didn't get any result for whether it's divisible or not divisible.
100
00:08:01,090 --> 00:08:07,320
So that's something good that happens, that we still just get some unexpected result.
101
00:08:07,330 --> 00:08:13,450
But sometimes the program may also crash and also you may get some unexpected results that you will
102
00:08:13,450 --> 00:08:17,220
not know from where it all started.
103
00:08:17,890 --> 00:08:22,420
So the problem here is very simple and but we should address it properly.
104
00:08:22,780 --> 00:08:30,460
And it says that what will happen if we will try to divide by zero and we know that the division by
105
00:08:30,460 --> 00:08:33,020
zero is not optional and it's not possible.
106
00:08:33,550 --> 00:08:41,140
So in this case, what I recommend you to do is simply to add before you use these this kind of division
107
00:08:41,680 --> 00:08:48,550
check, simply add additional condition to check if A equals to zero.
108
00:08:49,090 --> 00:08:49,610
Right.
109
00:08:49,630 --> 00:08:54,850
If A equals to zero or if B equals to zero.
110
00:08:57,600 --> 00:09:00,600
Or you've see equals three zero.
111
00:09:00,990 --> 00:09:04,730
If either of them equals to zero, then in this case, let's bring some message.
112
00:09:04,740 --> 00:09:10,380
Printf cannot divide by zero.
113
00:09:10,650 --> 00:09:13,800
Check your check your input once again.
114
00:09:14,370 --> 00:09:17,160
It's something like this, some descriptive message to the user.
115
00:09:18,600 --> 00:09:25,080
But if not, if it's not the case, if all of them, A, does not equal to zero, B does not equal to
116
00:09:25,080 --> 00:09:32,730
zero and C does not equal to zero, then in this case, let's execute these else if OK and finally execute
117
00:09:32,730 --> 00:09:33,440
the else.
118
00:09:34,530 --> 00:09:44,100
So that's how you kind of prevent unexpected behavior and also some unexpected errors and youguys.
119
00:09:44,100 --> 00:09:51,840
So we covered how to take three integers and to see if they can be divisible by by dividing them into
120
00:09:51,840 --> 00:09:58,440
pairs and if there is at least one number that can be divided by the other without a remainder.
121
00:09:59,070 --> 00:10:01,980
So, as always, thank you so much for watching.
122
00:10:02,070 --> 00:10:04,470
Thank you so much for practicing and listening.
123
00:10:05,040 --> 00:10:08,160
And my suggestion is close now.
124
00:10:08,910 --> 00:10:15,710
This exercise and the solution actually open up the exercise itself and try to solve it on your own.
125
00:10:16,110 --> 00:10:23,220
Make sure that the program that you create and you run will be pretty much the same, like the one we've
126
00:10:23,220 --> 00:10:23,770
created.
127
00:10:24,360 --> 00:10:27,870
So good luck, guys, and I will see you in the next exercises.
12644
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.