1
00:00:02,430 --> 00:00:03,300
Hi, guys.

2
00:00:03,390 --> 00:00:04,020
What's up?

3
00:00:04,560 --> 00:00:08,220
So today we are going to solve one more interesting problem on functions.

4
00:00:08,820 --> 00:00:12,960
So the Brownless statement is a function Laura done.

5
00:00:15,750 --> 00:00:16,980
Factorial of a number.

6
00:00:18,660 --> 00:00:20,210
Thought he'd done factorial over.

7
00:00:20,700 --> 00:00:21,120
No.

8
00:00:23,820 --> 00:00:24,770
So what is Vectorial?

9
00:00:25,350 --> 00:00:27,060
So five factorial.

10
00:00:27,140 --> 00:00:31,050
It was five to four and two, three in total.

11
00:00:31,170 --> 00:00:32,820
And doing what you can, right?

12
00:00:33,360 --> 00:00:35,760
One and two and two, three and two forward.

13
00:00:35,780 --> 00:00:36,170
And two.

14
00:00:36,320 --> 00:00:37,830
Five, which is 120.

15
00:00:38,790 --> 00:00:40,320
So what is one factorial?

16
00:00:40,930 --> 00:00:42,270
And there's one more.

17
00:00:42,280 --> 00:00:43,320
There's two factorial.

18
00:00:43,500 --> 00:00:44,670
It is one and two.

19
00:00:44,820 --> 00:00:46,690
Two or three factorial.

20
00:00:47,280 --> 00:00:49,890
One and two doing two, three, six.

21
00:00:50,310 --> 00:00:51,570
What is four factorial?

22
00:00:51,690 --> 00:00:52,230
One and two.

23
00:00:52,230 --> 00:00:52,800
Doing two.

24
00:00:53,010 --> 00:00:53,600
Three and two.

25
00:00:53,910 --> 00:00:54,250
Four.

26
00:00:54,390 --> 00:00:56,190
Which is twenty four.

27
00:00:57,030 --> 00:00:57,300
OK.

28
00:00:57,720 --> 00:01:05,130
So given a number and given a number, then we have to write a function that will on the factorial of

29
00:01:05,130 --> 00:01:05,960
that number.

30
00:01:08,530 --> 00:01:12,070
So how we can find factory number, for example, numbers.

31
00:01:12,220 --> 00:01:13,720
And so what do we do?

32
00:01:14,010 --> 00:01:16,540
One and two, two and three into four.

33
00:01:17,860 --> 00:01:18,160
And.

34
00:01:19,800 --> 00:01:22,420
OK, so I just we have to multiply all this numbers.

35
00:01:22,870 --> 00:01:23,770
So I need a loop.

36
00:01:24,130 --> 00:01:28,440
Initially, the loop will start from one Lowville go, then end.

37
00:01:29,080 --> 00:01:32,710
And what I will do, I will take a variable answer.

38
00:01:32,830 --> 00:01:34,320
Answer will initially be one.

39
00:01:34,720 --> 00:01:36,090
So answer quiz.

40
00:01:36,370 --> 00:01:36,820
Answer.

41
00:01:37,340 --> 00:01:38,620
Multiply by I.

42
00:01:39,970 --> 00:01:40,230
OK.

43
00:01:41,200 --> 00:01:41,860
So let's see.

44
00:01:49,910 --> 00:01:53,600
Function Factorial Nard CBB.

45
00:02:04,380 --> 00:02:10,500
So what I have to do, first of all, I will take a number and as input from the user who's Vectorial

46
00:02:10,500 --> 00:02:12,390
and we have to conclude.

47
00:02:13,810 --> 00:02:15,880
So we need a factorial function.

48
00:02:16,510 --> 00:02:19,710
Let's say the name of defect, all function is fact.

49
00:02:20,890 --> 00:02:25,690
It will take and as input was the toll, it has to return.

50
00:02:26,200 --> 00:02:29,410
So since it will be done something, I will have to store it.

51
00:02:29,770 --> 00:02:32,100
So let's say in Tancer, it was fact.

52
00:02:32,620 --> 00:02:36,430
Now, after getting the answer, I will print my answer.

53
00:02:36,910 --> 00:02:38,650
So that is all that we have to do.

54
00:02:39,040 --> 00:02:41,160
Now let us write the function fact.

55
00:02:41,740 --> 00:02:43,780
So this function will return an integer.

56
00:02:44,080 --> 00:02:47,950
That is the fact all of the number and the name of the function is fact.

57
00:02:48,310 --> 00:02:51,780
It will take a number as input was factory.

58
00:02:52,090 --> 00:02:53,140
It will calculate.

59
00:02:54,520 --> 00:02:54,910
So.

60
00:02:57,330 --> 00:03:01,230
Let's say I am having a variable and dasa, which is initialized to one.

61
00:03:02,520 --> 00:03:02,750
OK.

62
00:03:02,910 --> 00:03:06,660
And now we have to multiply starting from one.

63
00:03:07,050 --> 00:03:19,580
So I equals when I last then ordered close to an A plus plus answer equals answer my two blabby I.

64
00:03:21,300 --> 00:03:25,910
And after calculating the answer we have to read Dundy answer.

65
00:03:28,270 --> 00:03:29,860
OK, so this is all that we have to do.

66
00:03:30,670 --> 00:03:32,460
So now let us test our program.

67
00:03:35,880 --> 00:03:43,170
Led to the relief and is for so 24 is difficult enough for now, let's see, where does the factor of

68
00:03:43,170 --> 00:03:43,620
five?

69
00:03:43,710 --> 00:03:46,560
So the factor of five is one 20.

70
00:03:47,130 --> 00:03:48,810
So our program is working fine.

71
00:03:49,290 --> 00:03:55,050
And why I initially started with when I feel a lot initialise the answer will contain a garbage value.

72
00:03:55,260 --> 00:03:59,430
So we have to initialize, just like we used to initialize some equals zero.

73
00:04:00,030 --> 00:04:01,170
So we have to initialize it.

74
00:04:02,370 --> 00:04:07,170
So you can also start from two, because multiplication with one doesn't have an impact.

75
00:04:09,580 --> 00:04:11,020
So five victory leaves 120.

76
00:04:12,100 --> 00:04:19,030
One more thing that I want to tell you is so you people should not get confused, this variable answer

77
00:04:19,120 --> 00:04:20,500
and this variable answer.

78
00:04:20,590 --> 00:04:21,550
They both are different.

79
00:04:21,640 --> 00:04:21,880
Why?

80
00:04:21,880 --> 00:04:24,310
They are different because their scope are different.

81
00:04:24,670 --> 00:04:28,600
The scope of this variable answer is between this and this.

82
00:04:29,050 --> 00:04:32,050
And the scope of this answer is this.

83
00:04:32,530 --> 00:04:33,490
And this.

84
00:04:34,640 --> 00:04:38,030
OK, so here answer is a local variable.

85
00:04:38,750 --> 00:04:43,580
This is also a local variable and these scopes are different.

86
00:04:43,940 --> 00:04:46,820
OK, so these variables are different.

87
00:04:47,150 --> 00:04:48,290
Don't get confused.

88
00:04:48,590 --> 00:04:50,060
They don't have any relation.

89
00:04:50,420 --> 00:04:55,100
Also, this variable in and this variable and they're also different.

90
00:04:55,460 --> 00:05:01,610
The scope of this variable is between this bracket and this bracket, the scope of this variable and

91
00:05:01,750 --> 00:05:04,510
as between this record and this beckert.

92
00:05:04,910 --> 00:05:08,540
So I said and n they both are different.

93
00:05:08,890 --> 00:05:09,190
OK.

94
00:05:10,280 --> 00:05:11,720
They both are different.

95
00:05:12,390 --> 00:05:12,670
Why?

96
00:05:12,800 --> 00:05:14,690
Because their scores are different.

97
00:05:14,900 --> 00:05:16,460
So do not get confused at all.

98
00:05:17,120 --> 00:05:18,770
So let me show you what I want to say.

99
00:05:20,420 --> 00:05:24,770
So for example, I am changing the value of and let's say it was two.

100
00:05:26,100 --> 00:05:26,400
OK.

101
00:05:26,870 --> 00:05:34,340
And for example, I'm here I am bringing the value of an S.O.S. out.

102
00:05:35,720 --> 00:05:36,950
I'm bringing the videophone.

103
00:05:37,700 --> 00:05:39,080
And let's come into doubt.

104
00:05:41,450 --> 00:05:44,270
OK, so let's give fifers input.

105
00:05:45,260 --> 00:05:48,110
So I'm giving fifers input and I am printing the value of.

106
00:05:48,680 --> 00:05:48,830
So.

107
00:05:48,920 --> 00:05:50,570
Value and will not change.

108
00:05:51,050 --> 00:05:52,440
So five is getting printed.

109
00:05:52,790 --> 00:05:53,050
OK.

110
00:05:54,290 --> 00:05:55,280
So what I did is.

111
00:05:56,610 --> 00:05:59,300
So what I did I give five input.

112
00:05:59,660 --> 00:06:03,960
I call this function and this function change the value of N two two.

113
00:06:04,280 --> 00:06:08,250
But when I am printing the answer is still five.

114
00:06:08,270 --> 00:06:09,770
The value of end is still five.

115
00:06:10,060 --> 00:06:10,350
Why.

116
00:06:10,580 --> 00:06:13,890
Because this n and this n they are different.

117
00:06:14,290 --> 00:06:14,580
OK.

118
00:06:15,080 --> 00:06:17,960
They don't have any relationship and they're completely different.

119
00:06:19,310 --> 00:06:19,540
OK.

120
00:06:20,600 --> 00:06:21,890
So how are trends.

121
00:06:22,730 --> 00:06:23,780
This is my call stack.

122
00:06:23,810 --> 00:06:25,040
And this is my function.

123
00:06:25,040 --> 00:06:26,800
Main function mean.

124
00:06:26,900 --> 00:06:27,830
This is calling.

125
00:06:28,100 --> 00:06:32,600
It will call function in fact when in fact function will complete.

126
00:06:33,120 --> 00:06:34,510
When in fact function well you're done.

127
00:06:34,520 --> 00:06:35,540
It will be popped out.

128
00:06:36,680 --> 00:06:44,480
I will start executing my mean from line number 24 because this is coming command and then.

129
00:06:46,170 --> 00:06:49,950
When the work of mine gets completed, I will pop it out.

130
00:06:50,700 --> 00:06:55,880
And finally my Kostic will become empty and my programmers finish.

131
00:06:56,100 --> 00:06:56,340
Oh.

132
00:07:00,480 --> 00:07:04,850
OK, so remember this answer variable.

133
00:07:05,310 --> 00:07:12,540
This answer variable, completely different, this and this, and they are completely different.

134
00:07:13,200 --> 00:07:13,500
OK.

135
00:07:16,350 --> 00:07:19,650
So instead of storing you can directly, you can also print dramatically.

136
00:07:23,110 --> 00:07:30,040
You can also see out fact often and let's be clear, did.

137
00:07:36,810 --> 00:07:38,610
OK, so how does working.

138
00:07:40,810 --> 00:07:41,260
OK, guys.

139
00:07:41,350 --> 00:07:42,640
So this is it for this video.

140
00:07:43,900 --> 00:07:46,120
If you have any doubt, feel free to ask.

141
00:07:46,180 --> 00:07:46,690
Thank you.
