Salam Alaykum! This is Abdulrhman, a student
from King Faisal University.
We are in part 4 of a series of lessons in
C# using Console App. In this lesson we are
going to discuss Math class functions.
.NET has class library systems that are readily
available for us to use. One of them is the
Math class that has logarithmic and other
functions as well as constants E and PI.
Let’s do the 1st activity to apply it.
In this activity, we will ask a user for a
real number and will display its ceiling and
floor values.
If you want to try it on your own, please
pause this video now.
Let’s create a new project and name it CA4_1.
Here, we are going to ask for a float or a
double value. I prefer to use double. Later
we will make use of the Math.Ceiling and Math.Floor
functions.
Then we will display the results.
Let’s try to run it and enter 2.8.
The number 2.8 has a ceiling of 3 and a floor
of 2.
Well done!
In our 2nd activity we will create a .NET
Console App that will ask a user for 2 numbers
and will display the higher and the lower
values among the 2.
What Math functions are you going to use?
If you said Max and Min, then you are right?
If you want to do this alone, please pause
this video now.
To answer it, let’s create a new project
and let’s name it CA4_2.
We need to enter 2 numbers, and like in previous
problems, we need to convert them to numeric.
To get the higher of the 2 numbers, we will
use Math.Max function.
To get the lower of the 2 numbers, we will
use Math.Min function.
For a little change, we will display the results
in 2 lines by using the escape character backslash
n.
Now let’s try it. Please enter 7 and 3.
You can see that higher is 7, lower is 3.
Now here’s a challenge for you as you will
do it on your own. You have to modify our
last activity by using 3 numbers instead of
2.
Good luck!
In our next lesson we will be discussing condition
statements.
Thank you for visiting this channel!
