How to use sine() function in C
What is Function?
The function is a set of statements. It takes input and performs some computation to produce output.
The process is a set of codes only achieved when it is called. You can also pass data by using the function.
The C program produces some parts that are used to remove the program's complexity.
Many functions are used in the C language, but here we discuss the sine function in C.
Types of function –
There are mainly two types of function in C language, these are:
- Library function
- User definable function
Advantage of function –
- The function reduces the complexity of a program.
- The function gives a modular structure.
- This function can make its header file.
- It increases the readability of a program.
Sine function in C –
In the C programming language, the sine() function is a mathematical function. This returns the sine of a number.
The sin() function is a library function. It has another definition in trigonometry. This function is used to measure the unknown sides of a right triangle.
In which library is sine in C language?
The C library function, i.e. sin()
Syntax of sine function –
Double sin (double X);
The sin() function is returns some value. The is sine of the number.
Applies to –
In the C programming language, the sin() function is use in the following version, that is: ANSI/ISO 9899-1990
Parameter or argument of the Sine function –
The parameter of the sine function is x. x is a value that is expressed in radian. It is not used for defined the degree.
Returns value of the sine function –
Here we discuss the returns value. The sine() function is return a value. The value is a sine of x, measured by the radian, not by the degree. In the C programming language, we can write the sin function given below:
[Math] sin x = sin (x)
Header file of the sine function in C language –
Every program contains some header file, Which is necessary to run any program. Without using a header file, you can't run any program. So, we must produce a header file in every program. It is a file with an extension. The main use of the header file is to propagate the declaration of code files. Without header file we can not run any program.
The sine() function also known as the mathematical function.The header file of the sine function in C language is <math.h>.
It is written in the program as #include <math.h>.
The value of the sin() function must be lies between 0 and 1.
Example 1 –
Here we given a example of the sin() function using C language:
#include <stdio.h>
#include <math.h>
int main ()
{
//define temporary variable
double x ;
double result;
x = 2;
//calculate the sin value
result = sin (x)
printf (“sin(%.22f) = %.22f\n” ,x, result);
//assign the value
x = -2;
result = sin (x)
printf (“sin(%.22f) = %.22f\n” ,x, result);
x = 0;
result = sin (x)
printf (“sin(%.22f) = %.22f\n” ,x, result);
return 0;
}
Output
We compile and run the above program.The result of this above program is:
Sin (2) = 0.034
Sin (-2) = -0.034
Sin (0) = 0
For better understand, we are given another example of sin() function .
Example : Here we given the next example of the sin() function using C language:
#include <stdio.h>
#include <math.h>
#define PI 3.14
int main ()
{
//define temporary variable
Double x;
Double ret;
Double result;
//assign the value
x = 20.0;
//calculate the sine value
result = PI / 120;
ret = sin(x*result);
//print the result
printf (“Sine of the %1f is %1f degrees”, x, ret);
return (0);
}
Output – We are compile and run the above program.The result of this above program is:
Sine of the 20.0000 degrees is 0.02616666
In the above two programs, we have used the sine function; by the programs, we briefly discussed how to write any C language program using the sine() function.
The sine() function is a mathematical function.
So we <math.h> header file in this program. We also share the output of the above two programs.