×

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

Difference between Scope and Lifetime in C

In this article, we will discuss about the key differences between scope and lifetime in C, including their definitions, applications, and how they relate to one another. By the end...

8 minutes read.

Difference between Array and List in C

C# Array vs List is where the abstraction and implementation of human computing meet.  Arrays are incredibly related to the hardware concept of contiguous and contiguous memory, where each part is...

3 minutes read.

Big O Notation in C

Big O Notation in C: In the C programming language, we have so many algorithms and solutions to the problems that exist, which have different aspects and purposes to an...

3 minutes read.

How to use atoi() function in C

Introduction: The atoi() is a function used in C programming language. This function converts string characters to the integer value. The atoi() function converts the input string to the return type of...

4 minutes read.

C Array

An array is a collection of elements that are used to hold the fixed number of values of the same type. We cannot change the size and type of array...

2 minutes read.

Flow chart of While loop in C

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

3 minutes read.

Assert() Function in C

Assert (): In C, the statements are executed with the exit statement. In C language declare, and it tests the condition parameters. If the statement executed will be false, it shows...

4 minutes read.

How to include graphics.h in C?

How to include graphics.h in code blocks? Graphics .h is a header that allows drawing lines, rectangles, ovals, arcs, polygons, pictures, and strings on a graphical window by giving access to...

6 minutes read.

Top Array Keywords in C

Sorting array in C Types of array in C Array of structure in C How do you initialize an array in C Array declaration in C Array of strings in C Multidimensional array in C Reverse array...

1 minute read.

Queue implementation in C

In the C programming language, the queue is the abstract concept that is similar to stacks. However, it is the part of the data structures that work opposite to that...

4 minutes read.

Macros in C

In the C programming language, the macro is defined as a segment of the code replaced by the macro defined value at the beginning. ‘#define’ is the directive that defines...

3 minutes read.

Find Union and Intersection of Two Arrays in C

Union You can find the union of the two sorted arrays using the join merge method on arr1[] and arr2[]. Use two index variables i and j with initial values i =...

4 minutes read.

C Program to find the size of a File

Before knowing about the Program, you need to understand what the size of a file is. After that, you should know how it is going to work with the given...

4 minutes read.

abs() function in C

abs() function is a built-in function present in the stdlib.h header file. It returns an integer value. abs() function converts a negative value into a positive value. For example, if...

4 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.

Escape Sequence in C

An escape sequence is a sequence of character that used inside the string literal or character.  All the escape sequence is used with the backslash (\) symbol. The list of an...

1 minute read.

Variable Declaration in C

What is a Variable? A Variable is nothing more than a name for a memory place where data/information can be stored. Any alphabet (from a to z or A to Z), the...

4 minutes read.

Keywords in C

A keyword is a word that has a predetermined meaning. The C compiler knows the purposes of the keywords. The objectives of these keywords cannot be modified. Keywords are the...

9 minutes read.

Stack implementation in C

Stack implementation in C Stack stores the data in a particular order. It is a linear data structure that follows the principle of the Last In First Out (LIFO) technique where...

3 minutes read.

Bitwise XOR Operator in C

What is Bitwise? As we know, bits are the smallest unit of a number and are mostly used in a computing system. So, in bitwise, we do operations on bits instead...

3 minutes read.