Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,240 --> 00:00:02,820
So let's start with the solutions right away.
2
00:00:03,390 --> 00:00:08,610
First of all, what I want you to do is to specify the function type, and we know that a multiplication
3
00:00:08,610 --> 00:00:11,640
of the jurors will be equal to integers.
4
00:00:11,720 --> 00:00:14,690
So the function is going to return an integer type.
5
00:00:14,730 --> 00:00:16,610
So we just specify end.
6
00:00:17,190 --> 00:00:20,460
And now we specify the function name in these cases.
7
00:00:20,460 --> 00:00:22,000
Factorial four.
8
00:00:22,320 --> 00:00:24,390
Sorry about that factorial.
9
00:00:24,510 --> 00:00:27,220
And we know that a functional receives a number.
10
00:00:27,240 --> 00:00:28,590
So int num.
11
00:00:29,430 --> 00:00:33,240
Now we are going to specify the functions body and in the functions body.
12
00:00:33,240 --> 00:00:37,500
We are going to first of all, to make sure that the number is not negative.
13
00:00:37,530 --> 00:00:42,510
So if it is less, if NARM is less than zero.
14
00:00:42,590 --> 00:00:45,900
And in this case the function is going to return minus one.
15
00:00:45,900 --> 00:00:46,170
Right.
16
00:00:46,240 --> 00:00:52,850
That what we agreed on, that the function is going to return minus one if the number is less than zero
17
00:00:52,860 --> 00:00:55,600
and we can not calculate the factorial for it.
18
00:00:55,770 --> 00:01:00,090
So otherwise otherwise if that's not happening.
19
00:01:00,180 --> 00:01:00,420
Right.
20
00:01:00,450 --> 00:01:02,140
We do not need to.
21
00:01:02,190 --> 00:01:05,130
We are not required to use the yellow section here.
22
00:01:05,130 --> 00:01:07,380
We can just proceed with our code.
23
00:01:07,410 --> 00:01:14,010
Because if this line if this condition happened to be true, then we will simply return the result and
24
00:01:14,010 --> 00:01:17,310
we will not continue running the next lines of code.
25
00:01:17,370 --> 00:01:20,250
So there is no need for the yellow section here.
26
00:01:20,840 --> 00:01:25,220
Now, what we are going to do is to probably use some loop, right?
27
00:01:25,260 --> 00:01:26,700
We are going to use some loop.
28
00:01:27,060 --> 00:01:30,210
And I want us to use a loop.
29
00:01:30,360 --> 00:01:31,500
Let's use a for loop.
30
00:01:31,530 --> 00:01:39,690
So in it, I will create an IV variable and then we are going to specify the slope.
31
00:01:39,720 --> 00:01:45,220
So for I equals two one as long as I is less or equal to none.
32
00:01:45,270 --> 00:01:45,510
Right.
33
00:01:45,540 --> 00:01:51,780
Because we are going to multiply by I want every duration and I plus plus.
34
00:01:51,990 --> 00:02:01,080
And now what we are going to do is to multiply on each iteration, the number we have so far multiplied
35
00:02:01,080 --> 00:02:02,060
by I.
36
00:02:02,160 --> 00:02:04,290
So it will be one multiplied by two.
37
00:02:04,290 --> 00:02:04,980
By three.
38
00:02:05,070 --> 00:02:06,840
Until we reach these numbers.
39
00:02:06,990 --> 00:02:14,370
So for that what we also need, we need to create a in some some variable that will store the result.
40
00:02:14,490 --> 00:02:17,700
And let's call this variable been resolved.
41
00:02:18,300 --> 00:02:18,570
Okay.
42
00:02:18,630 --> 00:02:21,240
So the result will hold the result.
43
00:02:21,390 --> 00:02:24,930
The result of the factorial factorial.
44
00:02:25,680 --> 00:02:27,320
And now will also.
45
00:02:27,390 --> 00:02:28,490
What what should we do.
46
00:02:28,500 --> 00:02:31,090
Well, so we should specify some.
47
00:02:31,390 --> 00:02:35,130
We will we should initialize that these variable to be let's say one.
48
00:02:35,420 --> 00:02:35,760
Okay.
49
00:02:35,970 --> 00:02:38,940
This variable will be one end of every duration.
50
00:02:39,330 --> 00:02:41,760
We are going to multiply it by I.
51
00:02:42,120 --> 00:02:47,100
So result equals to the previous result multiplied by I.
52
00:02:47,670 --> 00:02:51,100
So on the first iteration we will have resolved.
53
00:02:51,390 --> 00:02:55,470
Equals to previous result which is one multiplied by one.
54
00:02:55,500 --> 00:02:55,920
All right.
55
00:02:56,010 --> 00:02:59,700
This operation may be actually unnecessary.
56
00:03:00,720 --> 00:03:01,440
In this case.
57
00:03:01,470 --> 00:03:02,760
But we'll leave it this way.
58
00:03:02,790 --> 00:03:05,710
So result equals the result multiplied by I.
59
00:03:06,150 --> 00:03:09,420
And on the next iteration it will be equal to one.
60
00:03:09,420 --> 00:03:10,830
Multiplied by two.
61
00:03:10,860 --> 00:03:11,130
Right.
62
00:03:11,160 --> 00:03:13,470
Because I is going to be equal to two.
63
00:03:13,530 --> 00:03:14,810
We incremented it here.
64
00:03:14,910 --> 00:03:19,980
And on the 30th duration, we will have previous result, which is two multiplied by three.
65
00:03:20,010 --> 00:03:21,450
And so on and so forth.
66
00:03:21,690 --> 00:03:25,620
And that's how you calculate the result in C programming language.
67
00:03:25,740 --> 00:03:32,940
And once you've calculated the result of the factorial of these number, you are going to return it.
68
00:03:33,210 --> 00:03:33,480
Right.
69
00:03:33,510 --> 00:03:35,580
So return result.
70
00:03:35,980 --> 00:03:37,050
And that's it.
71
00:03:37,200 --> 00:03:40,860
That's how you calculate the factorial for a given number.
72
00:03:40,880 --> 00:03:41,130
Right.
73
00:03:41,370 --> 00:03:42,870
So mathematical operation.
74
00:03:43,320 --> 00:03:47,430
We have written a function that will do this for us.
75
00:03:47,550 --> 00:03:54,330
Now, all that remains is simply to go to the main section and use some variable.
76
00:03:54,340 --> 00:03:56,730
It save my number.
77
00:03:56,790 --> 00:04:00,090
My num print a corresponding message.
78
00:04:00,120 --> 00:04:01,830
Enter the user.
79
00:04:01,830 --> 00:04:02,100
Right.
80
00:04:02,460 --> 00:04:09,510
Please, please insert insert a number that you want to calculate the factorial.
81
00:04:10,110 --> 00:04:12,120
So please enter the numbers.
82
00:04:12,150 --> 00:04:13,800
Can I have percentage the.
83
00:04:14,160 --> 00:04:21,990
You put it inside my now mine number and then you're are going to call these function and you are going
84
00:04:21,990 --> 00:04:23,410
to say all right.
85
00:04:23,430 --> 00:04:25,990
So are the factorial.
86
00:04:26,320 --> 00:04:26,820
All right.
87
00:04:26,970 --> 00:04:29,010
Let's say collectively as factorial.
88
00:04:29,460 --> 00:04:33,770
Here we will specify percentage the of the number itself.
89
00:04:33,810 --> 00:04:38,150
So percentage D equals two equals two percentage.
90
00:04:38,580 --> 00:04:41,060
And instead of the first percentage, B, right.
91
00:04:41,070 --> 00:04:46,950
Instead of this place holder, we are going to specify the number itself that we received from the user.
92
00:04:47,400 --> 00:04:54,660
And here, instead of these percentage D, we need to specify the result of the factorial on these given
93
00:04:54,660 --> 00:04:55,130
number.
94
00:04:55,140 --> 00:04:59,580
And the result is going to be the function we are calling the function with.
95
00:04:59,980 --> 00:05:04,840
No, and the function is going to return, the function is going to return.
96
00:05:04,870 --> 00:05:10,150
So instead of this function, here will be some return value, which is the result.
97
00:05:10,180 --> 00:05:14,920
We've calculated by multiplying this number of times.
98
00:05:15,010 --> 00:05:16,420
So I hope that's clear.
99
00:05:17,170 --> 00:05:20,480
We could we could use another variable in store.
100
00:05:20,650 --> 00:05:23,260
The result of the factorial inside of this variable.
101
00:05:23,290 --> 00:05:28,000
But for these exercises, that will be simply useless.
102
00:05:28,360 --> 00:05:36,250
So let's build and run it and see that both of our examples for these exercise works are so pleasing.
103
00:05:36,250 --> 00:05:37,070
Certain, no.
104
00:05:37,180 --> 00:05:38,290
Let's say three.
105
00:05:38,740 --> 00:05:41,440
So the factorial for three is six.
106
00:05:42,360 --> 00:05:44,170
And let's try the second number.
107
00:05:44,170 --> 00:05:45,470
It was five four.
108
00:05:45,480 --> 00:05:46,400
Make a mistaken.
109
00:05:47,020 --> 00:05:50,500
So the factorial for five is one hundred and twenty.
110
00:05:50,950 --> 00:05:58,810
So you've developed such a nice mathematical operation that you can also add to your calculator that
111
00:05:58,810 --> 00:05:59,620
you're developing.
112
00:05:59,710 --> 00:06:02,760
So thank you both for watching and I'll see you in the next video.
9197
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.