In mathematics, the sine function is among three primary functions, others comprising cosine and tan. Techniques for executing basic mathematical operations, like the elementary exponential, logarithmic, square root, and mathematical operations, are included in the header. You must include the header file to utilize these functions. The sin function accepts an angle in radians and gives its sine value, which can be confirmed using a sine curve.

You may use the law of sine to find any arbitrary angle in a triangle, as well as the length of a certain triangle side. This is a fundamental trigonometric notion. The sin function is used in the ANSI/ISO 9899-1990 versions of the C language. Sin () returns a result that is between 1 and -1.

Now, let us start with a few examples of sin() function in the C programming language.

Pre-requisites

  • Installation of GCC Compiler on Windows/ Linux

Note: We are using the GCC compiler in Windows 10.

Example 1

In our first illustration, we are going to use the sin() function in our program. Initially, you have to open a GCC compiler and create a new file with any required name. After that, insert the subsequent code into it.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-01.png" data-lazy- height="406" src="data:image/svg xml,” width=”936″>

We have added a few libraries that are and . Once added, move towards the main function. In the main() function, we have declared two variables, “a” and “result” with the double data type. To one of the variables, we have assigned it a value of “7.1” and calculated its sin value; the output will be stored in the “result” variable. Then we have assigned a negative value to variable “a” and calculated its sin value. After that, zero has been assigned to variable “a” and its calculating result will be stored in the “result” variable. Now we are all set to execute the program. In the menu bar of the GCC compiler, you have to click on the “Compile and Run” option to get the output. This option is present under the “Build” menu.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-02.png" data-lazy- height="274" src="data:image/svg xml,” width=”834″>

Once you click on this option, a black screen titled “Console” will appear on your screen. You will get the following affixed output as presented in the below-attached screenshot.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-03.png" data-lazy- height="182" src="data:image/svg xml,” width=”936″>

Example 2

In our second example, we will use the sin() function in our program in a little complex way. Initially, you have to open a GCC compiler and create a new file with any required name. The previous file can also be used. After that, insert the subsequent code into it.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-04.png" data-lazy- height="440" src="data:image/svg xml,” width=”936″>

We have added a few libraries that are and . We have added the value of PI, as can be seen in the screenshot. Once added, move towards the main function. In the main() function, we have declared three variables “a”, “retu”, and “value” with the double data type. To one of the variables, we have assigned it a value of “79.0”. We have applied a formula, saved its value in the “retu” variable, and calculated its sin value; then, we have printed the result using the printf() function. Now we are all set to execute the program. In the menu bar of the GCC compiler, you have to click on the “Compile and Run” option to get the output. This option is present under the “Build” menu.

Once you click on this option, a black screen titled “Console” will appear on your screen. You will acquire the following affixed output as presented in the below-attached screenshot.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-05.png" data-lazy- height="162" src="data:image/svg xml,” width=”936″>

Example 3

In our third and last example, we will use the sin() function in our program in a little different way. That user has to enter a number at run time to calculate the sin() value. Initially, you have to open a GCC compiler and create a new file with any required name. The previous file can also be used. After that, insert the subsequent code into it.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-06.png" data-lazy- height="386" src="data:image/svg xml,” width=”936″>

We have added a few libraries that are   and  . Once added, move towards the main function. In the main() function, we have declared two variables, “Sineval” and “num” with the double data type. We have used the printf() and scanf() function. After that, we will calculate the sin() of the value entered by the user and display its result.

Now we are prepared to execute the program. In the menu bar of the GCC compiler, you have to click on the “Compile and Run” option to get the output. This option is present under the “Build” menu. Once you click on this option, a black screen titled “Console” will appear on your screen. You will get the following affixed output as shown in the below-attached screenshot

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-07.png" data-lazy- height="144" src="data:image/svg xml,” width=”798″>

You can see that we have entered the “19” number and got its result as well. The number can be chosen as per your need.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Sin-function-C-08.png" data-lazy- height="264" src="data:image/svg xml,” width=”936″>

Conclusion

This article has provided a brief introduction regarding the sin() function in the C programming language. We have elaborated on three different examples for user understanding. All examples are different in implementation. Now, I hope whenever you try to implement these examples on your system, you can easily understand the basic concept of sin() function in the C programming language.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/d014e3711df41253029f4d4199698df8?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Kalsoom Akhtar

Hello, I am a freelance writer and usually write for Linux and other technology related content