Site icon Codeforcoding

Sine function in C programming Language

Sine function in C programming Language

In this tutorial, we will discuss Sine function in C programming Language

Sine function in C

Description

Description of  the C programming Language  Sin() function

In C programming language the sine function returns the sine of the radian angle x.

sin(): In the C programming Language this is used to calculate sine value to given radians.

Declaration

The Declaration of the sin() function

double sin(double x);

Parameter or Arguments

the parameter of the sine function is:

x – This is the floating point value of an angle and always measured in radians(not degrees).

Returns

The sin() returns the sine of x, measured in radians.

Required header

In the C language, the required header of the sin() function  in C

#include <math.h>

Example – Sin() in C programming

The following example shows the usage of sin() function

Program for Sine function in C

Program 1

#include <stdio.h>
#include <math.h>

int main()
{
    double x=0.5,y=1;//define and initiates variables

    printf("sine value of %f is %f\n",x,sin(x));
    printf("sine value of %f is %f\n",y,sin(y));
    getch();
    return 0;
}

 

When compile and run above program, this will produce the following result

sine value of 0.500000 is: 0.479426
sine value of 1.000000 is: 0.841471

Program 2

#include <stdio.h>
#include <math.h>
//sin calculator in C
int main()
{     //define variables
    float sineValue,inputValue;
        //Get input from user
    printf("please enter the value to calculate sine: ");
    scanf("%f",&inputValue);
        //Calculate the sine value 
    sineValue=sin(inputValue);
         //Display the sine value
    printf("\nThe sine value of %f is =%f",inputValue,sineValue);
    getch();
    return 0;
}

When compile and run above program, this will produce the following result

please enter the value to calculate sine: 2.56

The sine value of 2.560000 is  =0.549356

 

 

Similar Functions

Other C programming language functions that are  similar to the cosine function      

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

sqrt function in C language

pow function in C language

exp function in C language

log function in C language

log10 function in C language

trunc function in C language

 

 

suggested for you

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

 

cos function in C programming language
Exit mobile version