Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So let's start with the solutions right away.
First of all, what I want you to do is to specify the function type, and we know that a multiplication
of the jurors will be equal to integers.
So the function is going to return an integer type.
So we just specify end.
And now we specify the function name in these cases.
Factorial four.
Sorry about that factorial.
And we know that a functional receives a number.
So int num.
Now we are going to specify the functions body and in the functions body.
We are going to first of all, to make sure that the number is not negative.
So if it is less, if NARM is less than zero.
And in this case the function is going to return minus one.
Right.
That what we agreed on, that the function is going to return minus one if the number is less than zero
and we can not calculate the factorial for it.
So otherwise otherwise if that's not happening.
Right.
We do not need to.
We are not required to use the yellow section here.
We can just proceed with our code.
Because if this line if this condition happened to be true, then we will simply return the result and
we will not continue running the next lines of code.
So there is no need for the yellow section here.
Now, what we are going to do is to probably use some loop, right?
We are going to use some loop.
And I want us to use a loop.
Let's use a for loop.
So in it, I will create an IV variable and then we are going to specify the slope.
So for I equals two one as long as I is less or equal to none.
Right.
Because we are going to multiply by I want every duration and I plus plus.
And now what we are going to do is to multiply on each iteration, the number we have so far multiplied
by I.
So it will be one multiplied by two.
By three.
Until we reach these numbers.
So for that what we also need, we need to create a in some some variable that will store the result.
And let's call this variable been resolved.
Okay.
So the result will hold the result.
The result of the factorial factorial.
And now will also.
What what should we do.
Well, so we should specify some.
We will we should initialize that these variable to be let's say one.
Okay.
This variable will be one end of every duration.
We are going to multiply it by I.
So result equals to the previous result multiplied by I.
So on the first iteration we will have resolved.
Equals to previous result which is one multiplied by one.
All right.
This operation may be actually unnecessary.
In this case.
But we'll leave it this way.
So result equals the result multiplied by I.
And on the next iteration it will be equal to one.
Multiplied by two.
Right.
Because I is going to be equal to two.
We incremented it here.
And on the 30th duration, we will have previous result, which is two multiplied by three.
And so on and so forth.
And that's how you calculate the result in C programming language.
And once you've calculated the result of the factorial of these number, you are going to return it.
Right.
So return result.
And that's it.
That's how you calculate the factorial for a given number.
Right.
So mathematical operation.
We have written a function that will do this for us.
Now, all that remains is simply to go to the main section and use some variable.
It save my number.
My num print a corresponding message.
Enter the user.
Right.
Please, please insert insert a number that you want to calculate the factorial.
So please enter the numbers.
Can I have percentage the.
You put it inside my now mine number and then you're are going to call these function and you are going
to say all right.
So are the factorial.
All right.
Let's say collectively as factorial.
Here we will specify percentage the of the number itself.
So percentage D equals two equals two percentage.
And instead of the first percentage, B, right.
Instead of this place holder, we are going to specify the number itself that we received from the user.
And here, instead of these percentage D, we need to specify the result of the factorial on these given
number.
And the result is going to be the function we are calling the function with.
No, and the function is going to return, the function is going to return.
So instead of this function, here will be some return value, which is the result.
We've calculated by multiplying this number of times.
So I hope that's clear.
We could we could use another variable in store.
The result of the factorial inside of this variable.
But for these exercises, that will be simply useless.
So let's build and run it and see that both of our examples for these exercise works are so pleasing.
Certain, no.
Let's say three.
So the factorial for three is six.
And let's try the second number.
It was five four.
Make a mistaken.
So the factorial for five is one hundred and twenty.
So you've developed such a nice mathematical operation that you can also add to your calculator that
you're developing.
So thank you both for watching and I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.