Hello everyone, my name is (name) and we are continuing with this C programming course (6 seconds pause) in which in the last video we had discussed command line arguments.
We have seen how to run and compile a program when we type that command on the terminal.
At that time, we can also pass a few arguments and these arguments are accepted by the main function in our program and considering those arguments our program starts to work.
All these things we had discussed in the previous video.
In this video we have come up with a new topic and the topic of this video is C Inbuilt functions.
Now, we will see what exactly are these inbuilt functions and these inbuilt functions like we used to talk about our print-f or scan-f functions.
Apart from these there are other such functions which we were using.
As it is we call all these functions as inbuilt functions.
But what do they exactly mean? Where are they exactly coming from? All these things we are going to discuss in this video and in this topic.
So, without any delay, let's start and before understanding functions.
We will understand where exactly these functions come from.
So, these functions come to us from our library which means whenever we are writing a preprosesor command, at that time you must have seen that we import dot h file extension files.
So, these dot h extension files which are there, we call these as libraries and these libraries actually contain our inbuilt function’s function definition.
So, in these files the function’s definition.
So, in these files our function definition is already written from early on.
So, we could directly use these functions in our program, just the thing is that particular header file or that library in our program we import them in our program.
After that, we can use those functions.
So, what are libraries? “Header files are libraries which define some inbuilt functions that we can use without writing their function definition.” Like we had learned when we are making a function for our program.
We also have to write its function definition and what exactly that function will do for us.
So, all these function definitions are there in our libraries.
For what? For our inbuilt functions.
There are a few examples of inbuilt functions like our printf function or scanf function.
So, these functions we were not defining.
So, when we are saying, printf it exactly means this.
That you go to the terminal and print all these things over there.
All these things were already defined in which file, in our library and that library is called STDIO dot H.
So, what will we do in this particular program? We will learn about these libraries and then we will see what are the inbuilt functions of these libraries, which we can use in our program.
So, we are seeing all these libraries one by one.
After seeing the libraries, we will see their functions.
And those functions we will basically implement and see in our text editor, in our source code.
We will be implementing these and checking them.
We will quickly start with our very first header file, which is the first library.
We will discuss it.
So, the first library that we are discussing, it is called the math dot h library.
So, this header file’s math dot h, we come to know from its name itself that it is somewhere helping us mathematically to provide some functions.
So, how is it providing us the functions? We saw that when we had to do normal addition, subtraction, multiplication and division in our programs, in the C programming language.
We used to not import any extra header files to perform these operations but if I say, since we have learned a little bit of mathematics, if I say that in maths there are few trigonometry functions like sin, cos or the square root functions or the power functions or if I say the log functionality functions, in the mathematics.
If I want all those functionalities even in my C programming language, what will I do? I will import one library in my C programming language, which is called math dot h library.
So, this math.h library provides us with a lot of functions like trigonometric, logarithmic or power related functions.
So, it provides us with all these functions.
From these we will not be covering all the functions.
We will be seeing a few functions which we feel are very important.
So, these important functions which we use commonly like our square root function, or we have to put a power on any particular number like we say, 2 raised to 4 or 2 raised to 5.
So, in that scenario, how we would be solving it in our program.
So, these types of common functionality functions we would be seeing inside of math.h library, if I say what library is this, it is a library used for using mathematical functions.
There are a few examples of the functions that we will use.
SQRT, is one function in math.h.
Now what is this SQRT? Sqrt is a square root function.
So, we know that when we are calculating the square root, we put this bracket type sign over the number because of which we get to know that we have to calculate the square root of this number.
In the same way when we are using the sqrt function in our program, with that we get to know that here we are trying to calculate the square root.
If you see ahead, there is one more function named pow, pow means it represents power.
Whenever we want that we want to solve the power of a certain number.
If it is 2 raise to 5, 10 raise to 3.
To solve these kinds of problems, we use pow function, which means the power function.
In this what happens is that we provide both the numbers, which one will be on the subscript and which is the number of which we want to calculate the power of.
So, in this way our functions work, we will be seeing them practically in our text editor.
But for now, we will understand the overview over here.
In the same way is our log function.
Log function we know that it is used to find the log value, along with that there are cos and sin functions.
And all the other trigonometric functions, all are there defined inside math.h library.
So, we can use all of them over here but in this video we will be discussing five of these functions, which is the square root function, power function, log function, cos function and sin function.
So, this was about our math.h library.
Now we will quickly go to our text editor, there will use all these functions and check.
And then again we will go into our next library, where we will be discussing the next functions.
So, quickly we will go inside our text editor.
Here comes our text editor and you can see that here in the first line we have commented something, we have written something and it is telling me math.h functions which we are seeing in this video or in this program, their names our square root functions, power function, sin, cos and log functions.
In this way, we will be running our flow and we will first start our program.
In this entire program we will be only using math.h functions.
So, we will start with our program.
To start, the first important thing is to import the math.h library, included in our program.
So that we can use defined functions in those.
So, what we will do for that we will write here hash #include and we will write math.h like we used to write stdio.h.
Since we will be using printf and scanf functions here.
That's the reason why the stdio.h header file which is there, which we had discussed earlier as well as the printf and scanf functions which are there we can use for that.
So, both those things we will be importing here.
We will be including it here.
Now, we have talked about including our header files.
We have come ahead of it and we will be starting the main function.
What will we look at first in the main function? How one number’s square root can be calculated.
So, what we will be doing for this, we will be making two variables.
In the first variable we will be writing that number, of which we want to calculate the square root and in the second variable we would be basically storing its square root.
For that you can see here that we have made double data type two variables.
The first variable’s name is the number in which the number will come for which we have to calculate the square root and the second variable’s name itself is square root with which we understand that in that we will be storing the square root of that number.
Now we have come ahead and we are writing printf “Enter a number”.
So, what will the user be doing here? User will enter a number through our terminal and that number will be saved where? It will be stored in the number variable because we have used the scan f function over here.
Now we have got the number of which we have to calculate the square root.
Now how will we calculate the square root? We will be calculating the square root with the sqrt function.
We will see how it works.
Our sqrt function is extremely simple.
We only have to pass the number in it for which we want to calculate the square root.
So, here in the number variable the value that is stored, we want to calculate the square root of it.
So, for that what we will do, in the sqrt function bracket, we will write the number and whatever it returns, what will the sqrt function return? It will return the square root.
We will store it or assign it in our square root variable, that's why we have written this statement, whatever is returned by the sqrt function, it will come and get stored in our square root variable.
Now, here we have got the square root that's why we will be printing it with the help of printf statement.
And we will say, the square root of the number that you have provided is equal to whatever the square root has come.
So, this was about our square root function.
Now, we will run it and see how we are able to calculate the square root over here.
So, for that we will be running it over here and we will write the file’s name over here and as soon as we compile it, you can see that it has been successfully compiled.
There is no error that has come here.
So, what we will do here is we will run it in our command prompt because in PowerShell, sometimes we can see errors.
So, we will again run it over here, “gcc maths hyphen header” is our file’s name dot c is the file extension and we will type the character and press enter.
Now, it is asking us for a number for which we have to calculate the square root.
We know that 3 is the square root of 9.
Right? 3 times 3 is 9.
That's why we will write here nine itself and we will check whether the square root it gives is correct or not.
So, “square root of 9 = 3.” In this way, you can see how it has calculated the square root for our number.
In the same way, whichever number’s square root you want to calculate, whether it's a proper square root or not.
Even then you can calculate it over here.
Because we have used a double data type over here.
Even if the values come in decimal, even then it will calculate and give us.
Now we spoke about our square root function and now we will speak about power function.
For that what I will do is I will bring one code over here and I will remove the square root program from here.
So, here comes my power program.
We will understand first, what exactly we are trying to do here.
You know that whenever we want to calculate the power of any number, in that the below number we call it as base number.
The above number we call it as power.
That is the reason why we have defined three variables over here in which the first variable, we will store as the base number.
In the second variable what we will be storing is our power, whichever power we wish to calculate and in the third variable we would be storing its result.
So, one by one we have taken input of base and power from the user.
You can see that with the help of printf and scanf statements.
We have taken the input in base and power.
Now we will talk about our POW function, which is the power function.
What do we have to pass in the pow function? We have to pass both the value base and power values.
First of all, we will have to pass the base number, in the bracket of pow function.
That's the reason why we have first passed the base and after putting the comma the second power variable where we had kept that power is basically what we have passed over here.
Whatever the pow function will return that will be stored in our result variable and we will be printing it over here with the help of printf statement.
So, this was about our POW function.
Now we will save it and we will run it and see.
To run it I will use the same command over here.
You can see here that it has been successfully compiled over here.
Now we will execute it.
Now this is asking me my base number so what will I do? I will pass 4 as the base number.
Now it is asking me how much power we have to put over it.
Which means 4 raised to how much it should be.
For now I will keep here 2.
So, what I have done is basically tried to find 4 squares over here.
As soon as I press enter over here you can see that we know the square of 4 is 16.
That's why it has passed 16, in the output and given it to us.
In the same way you can calculate the square, cubes of any numbers or any power that you have to raise for any base number.
That you can write here and generate its output.
So, this was about our power function, POW function.
Now we will come to our next function.
This is our logarithmic function.
What will happen in this is we will be using one log function and we will be passing one value in it and the value’s log will find us our log function.
So, this is our log function.
In the log function, you can see that we have defined one variable, in which by default we have given one value which is 5.6 and 5.6 we have stored in a num variable.
Along with that we have also made a result named variable and what will this result variable do? It will store the result of the log value in itself and then we will print it over here.
So, you will see how we print it.
First of all in the log function we passed a variable named NUM .
And we know which value is there in n u m.
There is 5.6 value stored over here.
So, 5.6 has come to us, so in the log we have passed 5.6.
Whichever log will be 5.6 that will be stored in our result and come.
We will first of all run it as we have taken the help of printf statement.
You can see here that the format specifier that we have used here is slightly different.
How is it different? If we want to pass normal, what we would do, we would pass it just like this but we have used point 1 over here.
So, the meaning of using point 1 is that the decimal values by default which we get as 5 and 6, will get limited to one decimal value.
In the same way you can see that on the other side we have put point 2, so this value will be limited to point 2.
So, we will save it once and we will run it and see over here.
So, we will quickly go into our terminal and we will run it.
You can see that over here the program has been successfully compiled and now we will press enter.
Now you can see here that the value of log 5.6, it has passed 1.72 and given it to us.
Now we can see over here log 5.6 has been calculated with the help of log function.
Here since we have used point 2 and so after the decimal only two values have been printed, otherwise you can see that here 4 more decimal values could have been printed.
If we wouldn't have put .2 or .1.
So, this was about our log function.
Now we will quickly see the sin function.
We know what sin does.
Whenever we are using trigonometry, whenever we are using triangles, their sin function cosin function, in the same way tan function, all these functions come to use for us.
If the same thing happens, we want to run the program, how if we are keeping x value as 2.3, sin of 2.3 If we wish to calculate, what exactly is the output that it will give us.
So, that we will see here quickly.
So, this is our simple program.
Here in the x variable we have stored 2.3.
Along with that in the sin function we have passed x, whoever will return the sin function for us that we will be storing in the result variable and that result variable, we will be printing with the help of printf statement.
So, we will save it and run it again…..now it is telling us that the result is undeclared.
Why is it undeclared? Because we have not written any data type of the result.
So, we will write its data type as double and after that we will save it and we will try to execute it again over here.
So you can see that we are passing the same statement over here again.
Now it is telling us that x is undeclared, even x we have not declared over here.
Here basically both of them we have not declared.
So we will declare both of them over here.
After that we will run it and see.
Now this program has run successfully.
Now we will compile it and run it again and see.
So, you can see that sin 2.3, its value it is printing and giving us, is 0.75.
Like this all functions like sin, cosin, tan function.
All the functions which are provided to us by math dot h library, we can explore all those functions over here.
So, this was about math.h library functions.
How we can use their functions.
How we have to import math.h function, include it.
And these functionalities and these functions, in that which all parameters and arguments we have to pass.
All these things we have seen in this particular video.
If you think that there is any part of this video or this topic, you might have not understood then you can ask us any query or question related to that topic without any inhibition.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
In the next video we will see similar types of header files which are the string.h header files or the time.h header files.
We will be seeing all these header files in our next video.
Till that time you practise all the functions of math.h.
We will meet soon in the next video.
Share a personalized message with your friends.