Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,500 --> 00:00:06,850
So now that you tried to solve this exercise on your own, let's give it a shot together, shall we?
2
00:00:07,640 --> 00:00:13,100
And first of all, we have to understand is let's just use the example, the previous example that we
3
00:00:13,100 --> 00:00:18,860
have some data variable needs of a floating point, floating point type.
4
00:00:19,100 --> 00:00:19,460
Right.
5
00:00:20,060 --> 00:00:27,860
And for example, we had like twelve point seven with what we are requested to do is to extract these
6
00:00:27,860 --> 00:00:32,430
information, these zero point seven after the decimal point.
7
00:00:33,530 --> 00:00:41,060
So first of all, what I want us to do is just a quick reminder of how would you extract just the integer
8
00:00:41,060 --> 00:00:41,790
type, right.
9
00:00:41,840 --> 00:00:44,450
Just these 12 without a point seven.
10
00:00:44,900 --> 00:00:50,570
And based on the result and based on the way that we are going to do it and the way that we've done
11
00:00:50,570 --> 00:00:55,200
it previously, we are going to extract also these points zero.
12
00:00:55,580 --> 00:01:02,890
So I hope you're ready to get yourself something nice to drink or maybe a pen and to write some notes.
13
00:01:02,900 --> 00:01:04,470
And here we go.
14
00:01:05,390 --> 00:01:13,960
So the first thing that we have to do is to create to declare a variable float data, write right after
15
00:01:13,970 --> 00:01:14,420
words.
16
00:01:14,430 --> 00:01:17,950
We are going to read these data, these value from the user.
17
00:01:17,960 --> 00:01:26,780
So print f, print F, enter the data of floating point tied, for example.
18
00:01:26,930 --> 00:01:33,920
OK, here we are going to read these data from the user by using this kind of function and we are going
19
00:01:33,920 --> 00:01:38,730
to use the percentage F and to write it into data.
20
00:01:38,810 --> 00:01:40,730
That's how we are going to solve it.
21
00:01:40,820 --> 00:01:42,470
OK, so that's the first step.
22
00:01:43,280 --> 00:01:51,320
Now what we have to do is if we want to print the integer itself, for example, the twelve, the full
23
00:01:51,320 --> 00:02:00,590
part of these decimal number, what we have to do is simply just print half the decimal or the integer.
24
00:02:00,830 --> 00:02:01,910
The integer better.
25
00:02:01,970 --> 00:02:05,540
The integer path equals to percentage deep.
26
00:02:06,050 --> 00:02:11,600
OK, instead at least percentage we if we would have used data.
27
00:02:11,720 --> 00:02:14,000
OK, then let's see what will happen.
28
00:02:14,030 --> 00:02:15,140
So build and run it.
29
00:02:15,650 --> 00:02:21,220
Let's say we have twelve point seven and you will see some really strange number.
30
00:02:21,220 --> 00:02:23,050
Right, one six one oh six.
31
00:02:23,060 --> 00:02:24,500
Well what is that.
32
00:02:25,070 --> 00:02:27,640
I'm trying just to get the percentage of data.
33
00:02:28,520 --> 00:02:31,060
So there is a problem here.
34
00:02:31,070 --> 00:02:33,140
Why didn't we get just 12?
35
00:02:33,440 --> 00:02:37,880
And the reason is very simple, because data is stored as a float.
36
00:02:38,120 --> 00:02:39,950
Right, as a floating memory.
37
00:02:40,400 --> 00:02:43,940
And we are trying to read this information is an integer.
38
00:02:43,940 --> 00:02:46,850
So here we have a problem.
39
00:02:46,880 --> 00:02:53,960
OK, I'm not going to dive into all the details, into all the bytes and bits, let's say, of this
40
00:02:53,960 --> 00:02:56,150
variable and how it's being read.
41
00:02:56,300 --> 00:03:03,080
But simply know that if you store it as a float and you're trying to read it without any explicit casting
42
00:03:03,080 --> 00:03:08,150
as an integer, then unexpected behavior may occur.
43
00:03:08,990 --> 00:03:17,330
So what you have to do is, for example, to use explicit casting and to specify here and OK, so that's
44
00:03:17,330 --> 00:03:18,470
an explicit casting.
45
00:03:18,680 --> 00:03:25,970
And if we are going to build and run it, you will see that you get the integer parts 12, because you
46
00:03:25,970 --> 00:03:33,560
know that INT is an explicit casting if you use it this way and it will simply take the integer part
47
00:03:33,770 --> 00:03:38,130
of a given floating point number like we have here with data.
48
00:03:38,810 --> 00:03:41,510
So I hope that's clear, right.
49
00:03:41,540 --> 00:03:42,740
No questions about it.
50
00:03:42,740 --> 00:03:45,970
If you still have any questions, feel free to ask them.
51
00:03:46,760 --> 00:03:55,220
And all that remains right now is to pretend not the integer part, but rather the decimal part after
52
00:03:55,250 --> 00:03:56,430
the decimal point.
53
00:03:57,320 --> 00:03:58,900
So how it can be done?
54
00:03:59,600 --> 00:04:08,300
It's actually it's very simple because you know that the initial data is twelve point seven, for example,
55
00:04:08,300 --> 00:04:12,390
and we know how to get the integer part of the full part of it.
56
00:04:12,890 --> 00:04:19,650
So if we will take the initial the actual data and subtracted with it, well, OK.
57
00:04:19,670 --> 00:04:26,720
So if we use something like this so we know how to get the twelve and we are going to use twelve point
58
00:04:26,720 --> 00:04:29,630
seven minus twelve and it will give us.
59
00:04:29,660 --> 00:04:31,490
What do you think it will give us.
60
00:04:31,670 --> 00:04:39,320
Zero point seven, which is exactly the floating point, the decimal path that we wanted to get.
61
00:04:39,800 --> 00:04:42,050
So how should we do it?
62
00:04:42,050 --> 00:04:51,470
So Preens have proven to have the decimal part, that same old part after the floating point.
63
00:04:51,590 --> 00:04:59,950
After the floating point equal is two percentage F and here instead of the percent.
64
00:05:00,080 --> 00:05:07,220
Jeff Placeholder, we are going to take the data, right, that's the initial data and use subtraction
65
00:05:07,220 --> 00:05:10,260
of input data.
66
00:05:11,690 --> 00:05:17,690
So we simply took twelve point seven minus 12.
67
00:05:17,690 --> 00:05:20,440
Right, because we take just the integer path.
68
00:05:20,450 --> 00:05:29,330
And basically what we got is the decimal part out of a hold of a given floating point variable, out
69
00:05:29,330 --> 00:05:31,610
of a given floating point value.
70
00:05:31,640 --> 00:05:34,400
So let's let's build and run it and see what happens.
71
00:05:34,760 --> 00:05:39,120
So enter the data floating point type, let's say twelve point seven.
72
00:05:39,470 --> 00:05:40,550
And there you go.
73
00:05:40,550 --> 00:05:42,740
The decimal part is this one.
74
00:05:42,750 --> 00:05:46,090
The integer part is that one freaking awesome.
75
00:05:46,880 --> 00:05:51,440
And what now we have to do let's do another example.
76
00:05:51,470 --> 00:05:53,180
We don't have to do anything right now.
77
00:05:53,690 --> 00:05:54,230
Basically.
78
00:05:54,230 --> 00:06:00,500
No, there was one thing that wanted to do is simply to kind of limit to the number of zeroes that we
79
00:06:00,500 --> 00:06:01,030
can see.
80
00:06:01,040 --> 00:06:02,580
Two point one, for example.
81
00:06:02,580 --> 00:06:02,840
Okay.
82
00:06:02,870 --> 00:06:05,200
Or point to let's make it like this.
83
00:06:05,630 --> 00:06:10,120
So let's say five point seventy five.
84
00:06:10,130 --> 00:06:17,840
So we expect the integer part to be five and the decimal bar to be zero point seventy five five and
85
00:06:17,840 --> 00:06:19,510
zero point seventy five.
86
00:06:20,090 --> 00:06:20,570
Awesome.
87
00:06:20,570 --> 00:06:22,720
Guys, I think that's amazing.
88
00:06:22,970 --> 00:06:24,230
Good job.
89
00:06:25,790 --> 00:06:32,480
I guess that by now you start feeling like you're more confident with your knowledge and with applying
90
00:06:32,480 --> 00:06:36,080
your skills in our C programming language.
91
00:06:36,920 --> 00:06:40,160
So keep on practicing, keep on working hard.
92
00:06:40,550 --> 00:06:49,130
And trust me, guys, there is no reason why if you have a lot of free time, I hope you do.
93
00:06:49,130 --> 00:06:56,480
If not, try to find always some balance, try to find some free time to exercise and to solve more
94
00:06:56,480 --> 00:06:57,200
exercises.
95
00:06:57,680 --> 00:07:01,940
You're not wasting time for those of you who say, oh, that's very easy.
96
00:07:01,940 --> 00:07:02,900
I know this one.
97
00:07:02,900 --> 00:07:04,030
I know how to solve this one.
98
00:07:04,370 --> 00:07:07,130
No, it's it's not the case.
99
00:07:07,130 --> 00:07:10,220
It's the more you practice, the better you will be.
100
00:07:10,400 --> 00:07:13,700
The more you learn, the smarter you probably will be.
101
00:07:14,060 --> 00:07:21,770
So take your time, put in the hustle the hard work, and I guess you are about to succeed.
102
00:07:22,400 --> 00:07:23,780
So my name is Vlad.
103
00:07:23,990 --> 00:07:25,160
This is Alphatech.
104
00:07:25,520 --> 00:07:28,430
Thank you so much for watching and I will see you next time.
9626
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.