The C sin Function is a Math Library Function used to calculate the trigonometric Sine value for the specified expression. The syntax of the sin() function is as shown below.
double sin(double number);
The sin function will return a sine value between -1 and 1. Before we get into the syntax of a sin function, let us see the mathematical formula behind this Trigonometry Sine:
sin(x) = Length of the Opposite Side / Length of the Hypotenuse
sin function in C Example
The sin function in the math library allows you to calculate the trigonometric Sine for the specified values. This program asks the user to enter his/her own value. And then it will find the sine value of the user-specified value.
TIP: Please refer to the asin function and math functions articles to calculate the Arc Sine of a specified expression.
#include <stdio.h>
#include <math.h>
int main()
{
double sinValue, number;
printf(" Please Enter the Value to calculate Sine : ");
scanf("%lf", &number);
sinValue = sin(number);
printf("\n The Sine value of %lf = %f ", number, sinValue);
return 0;
}

How to convert degrees to radians in C for the sin() function?
By default, the sin() function does not accept degrees as the parameter value. So, if we want to find the sine value of degrees, we must explicitly convert the degrees to radians and then apply the sin() function.
This C Programming example allows the user to enter the value in degrees, and then we convert the degrees to Radians. And finally, we are finding the sine value of the radian.
#include <stdio.h>
#include <math.h>
#define PI 3.14159
int main()
{
double sinValue, radianVal, degreeVal;
printf(" Please Enter an Angle in degrees : ");
scanf("%lf", °reeVal);
// Convert Degree Value to Radian
radianVal = degreeVal * (PI/180);
sinValue = sin(radianVal);
printf("\n The Sine value of %f = %f ", degreeVal, sinValue);
return 0;
}
Please Enter an Angle in degrees : 30
The Sine value of 30.000000 = 0.500000
TIP: Please refer to the cos and tan functions to find the cosine and tangent values.
C sinf and sinl functions
Along with the C sin() function, there are two other variants, such as sinf() and sinl() methods, to find the sine value of the given float and long double values.
- If the data type is double, use the sin() function.
- Use sinf() function when the data type is a float, and to get the result as a float. The sinf() function avoids converting a float to double and then converting the result back to a float.
- Similarly, if the data type is long double, use the sinl() function.
In the following program, we use the sinf() and sinl() functions to find the sine value of a floating-point number and long double data type.
#include <stdio.h>
#include <math.h>
int main()
{
double a = 1.0;
double res1 = sin(a);
printf("%.2f\n", res1);
float b = 1.57f;
float res2 = sinf(b);
printf("%.2f\n", res2);
long double c = 0.75L;
long double res3 = sinl(c);
printf("%.2Lf\n", res3);
}
0.84
1.00
0.68