×

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:

  1. Library function
  2. User definable function

Advantage of function –

  1. The function reduces the complexity of a program.
  2. The function gives a modular structure.
  3. This function can make its header file.
  4. 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.


Related Topics

Actual and Formal Parameters

Any variable declared within the parenthesis is referred to as the parameters during the function declaration. Parameters tell the function about the argument datatype, their order, and the number of...

5 minutes read.

Bar3d() function in C Graphics

The bar3d function is used to create a 2-dimensional filled-in rectangular bar. We can also create three-dimensional shapes in C using helpful function. The first step in creating this 3D...

3 minutes read.

Limitations of Synchronisation and Uses of Static Synchronisation in Multithreading

The multithreading component of java is the element around which the idea rotates as it permits simultaneous execution of at least two program pieces for the most significant usage of...

9 minutes read.

Snake Game in C

Snake game in C is basic desktop console program which was created in 1970’s. It is an old classic game which was played by every child across the world. This...

4 minutes read.

Addition of Matrix in C

The mathematical operation of includingor greater matrices is called the addition of matrices. A matrix is a square series of numbers, symbols, words, letters, and different things. In this article,...

3 minutes read.

Errors in C

Errors in C Errors are nothing but problems or faults that pretty much occur in all the programming languages. Errors make the behavior of the program seem abnormal, and even the...

4 minutes read.

C Language Environment Setup

To compile C program, we must have GCC compiler installed on our machine. In this C tutorial, all the examples are compiled and tested using GCC compiler. Although we can...

3 minutes read.

Commenting in C

Commenting in C Commenting in the C language is used to give out the information about the lines of the code which are included. It is one of the things that...

3 minutes read.

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

Variables in C

A variable can be defined as a name allocated to a storage space that can be manipulated by our programs. Every variable in C arbitrates about the overall layout and...

5 minutes read.

Classification of Programming language

 Classification of Programming language  The programming language represents a set of instructions compiled along with each other to perform a specific task provided by the CPU (Central Processing Unit). A programming...

3 minutes read.

OpenGL in C

OpenGL stands for Open Graphics Library. It is a low-level, widely supported modeling and rendering software package that is widely available across all the platforms. It is an API used...

4 minutes read.

C Program Swap Numbers in cyclic order Using Call by Reference

The three integers that the user entered in cyclical sequence are swapped in this tutorial using call by reference. C Program: #include <stdio.h> void cyclic_Swap ( int *X, int *Y, int *Z ); int...

2 minutes read.

Call Back Function in Embedded C

Callback function are one the most remarkable systems in C. A callback function is any code that is passed as a contention to another code, so this is the last...

3 minutes read.

Recursion in C

Recursion is a programming technique that allows the programmer to call the function within the same function. The function which calls the same function is known as recursive function but a...

1 minute read.

C vs Java Strings

String in C In C, we can define a string as a bunch of characters. A character array is distinguished from a string by the presence of the special character '\0'...

5 minutes read.

Flow Chart of For loop in C

This is a flowchart that represents the process of executing the for loop in the C programming language. Generally, as we know there are three main components of for loop:1. The...

3 minutes read.

Array to function in C

Array to function in C We can create functions that receive an array as an argument. To pass an array into a function, we need to write the name of the...

4 minutes read.

2f in C language

Float data type in c: Double-precision floating-point numbers with up to 17 significant digits are stored in the FLOAT data type. FLOAT is equivalent to C's double data type and IEEE...

3 minutes read.

How to Avoid Structure Padding in C

Generally, when an object of some structure type is declared, some contiguous memory will be allocated in block form, which will be allocated to structure members. To understand structure padding...

3 minutes read.