C Math sin() Function

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
<math.h>

What You’ll Learn

The sin() function computes the sine of an angle. In C, the angle must be in radians. The result is always between −1 and 1—the building block for waves, oscillations, and circular motion.

01

Sine

Trig function.

02

math.h

Link with -lm.

03

Radians in

Not degrees.

04

Range

[−1, 1].

05

Unit circle

y-coordinate.

06

vs sinh

Different fn.

Definition and Usage

Sine relates an angle to a ratio on a right triangle: opposite ÷ hypotenuse. On the unit circle (radius 1), sin(θ) is the y-coordinate at angle θ.

In C, sin(x) expects x in radians. One full turn is radians (360°). A quarter turn is π/2 radians (90°).

💡
Beginner Tip

60° is M_PI / 3.0 radians, and sin(M_PI / 3.0) is about 0.866. Do not pass 60 directly—that is 60 radians, not 60 degrees. C has no built-in deg2rad; use degrees * M_PI / 180.0.

📝 Syntax

Standard C declaration:

C
double sin(double x);

Related variants

C
float sinf(float x);           /* <math.h> */
long double sinl(long double x); /* <math.h> */

Parameters

  • x — angle in radians.

Return Value

  • Sine of x, in the range [−1, 1].
  • sin(0) returns 0.0; sin(M_PI / 2) returns 1.0.
  • sin(M_PI) returns 0.0 (within floating-point tolerance).

Headers and linking

  • #include <math.h>
  • Compile: gcc sin.c -std=c11 -o sin -lm
  • On MSVC, define _USE_MATH_DEFINES before <math.h> for M_PI.

⚡ Quick Reference

CallAngleResult
sin(0)0.0
sin(M_PI / 6)30°0.5
sin(M_PI / 3)60°0.866 (√3/2)
sin(M_PI / 2)90°1.0
sin(M_PI)180°0.0
Forward
sin(angle)

Radians in

Degrees
deg * M_PI/180

Convert first

Partner
cos(angle)

x on circle

Not this
sinh(x)

Hyperbolic

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. All angles below are converted to radians before calling sin().

📚 Getting Started

Compute sine of a common angle and print the result.

Example 1 — Sine of 60 Degrees

Classic example from the reference: convert 60° to radians, then call sin().

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    double degrees = 60.0;
    double radians = degrees * M_PI / 180.0;
    double result = sin(radians);

    printf("Sine of %.1f degrees (%.3f radians): %.3f\n",
           degrees, radians, result);

    return 0;
}

How It Works

60° equals π/3 radians. On a unit circle, the y-coordinate at that angle is √3/2 ≈ 0.866.

Example 2 — sin(0) and sin(π/2)

Two anchor values every student should know.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    printf("sin(0)      = %.1f  (0 degrees)\n", sin(0.0));
    printf("sin(M_PI/2) = %.1f  (90 degrees)\n", sin(M_PI / 2.0));

    return 0;
}

How It Works

At 0° the point is (1, 0)—sine (y) is 0. At 90° the point is (0, 1)—sine is 1.

📈 Practical Patterns

Degree conversion, wave sampling, and comparison with cos.

Example 3 — Reusable Degrees-to-Radians Helper

Wrap the conversion so you never forget radians.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

static double deg_to_rad(double degrees) {
    return degrees * M_PI / 180.0;
}

int main(void) {
    double angles[] = { 0.0, 30.0, 45.0, 60.0, 90.0 };
    size_t i;

    printf(" deg    sin()\n");
    for (i = 0; i < 5; i++) {
        double rad = deg_to_rad(angles[i]);
        printf("%4.0f  %6.3f\n", angles[i], sin(rad));
    }

    return 0;
}

How It Works

A small helper keeps degree math out of your trig calls. This table matches standard trigonometry values.

Example 4 — Sample a Sine Wave

Print sine values at several angles to see the wave shape—common in audio and animation.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    int deg;

    printf("deg   sin()\n");
    for (deg = 0; deg <= 90; deg += 15) {
        double rad = deg * M_PI / 180.0;
        printf("%3d  %6.3f\n", deg, sin(rad));
    }

    return 0;
}

How It Works

Sine rises smoothly from 0 to 1 over the first quarter-turn. Animating sin(time) creates repeating oscillation.

Example 5 — sin() vs cos() at Key Angles

See how the two basic trig functions complement each other on the unit circle.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    double angles[] = { 0.0, M_PI / 2, M_PI };
    const char *labels[] = { "0", "pi/2", "pi" };
    size_t i;

    printf(" angle   sin()   cos()\n");
    for (i = 0; i < 3; i++) {
        printf(" %5s  %5.1f  %5.1f\n",
               labels[i], sin(angles[i]), cos(angles[i]));
    }

    return 0;
}

How It Works

At 0°, sine is 0 and cosine is 1. At 90°, they swap. Remember: sin = y, cos = x on the unit circle.

🚀 Common Use Cases

  • Graphics and games — bobbing motion, pendulums, circular paths (y = r * sin(θ)).
  • Audio synthesis — pure tones are sine waves at a given frequency.
  • Physics — simple harmonic motion, springs, and pendulums.
  • Signal processing — model periodic AC voltage and vibrations.
  • Pair with cos() — full 2D position from angle and radius.

🧠 How sin() Works

1

Receive radians

Angle x in radians (convert from degrees if needed).

Input
2

Evaluate sine

Library computes sin using optimized polynomial or hardware instructions.

Compute
3

Return in [−1, 1]

Result is a double representing the y-component on a unit circle.

Output
=

Sine value

Multiply by radius for real-world distances: y = r * sin(θ).

📝 Notes

  • Input is radians, not degrees—convert with degrees * M_PI / 180.0.
  • Output is always in [−1, 1].
  • sin() is an odd function: sin(-x) == -sin(x).
  • Link with -lm when using GCC/Clang on Unix-like systems.
  • Do not confuse sin() with sinh() (hyperbolic sine).
  • For very large angles, floating-point precision can affect results—consider reducing the angle modulo if needed.

⚡ Optimization

sin() is implemented in the platform math library and is typically fast enough for most applications. If you call it thousands of times per frame in a game loop, profile first—often the bottleneck is elsewhere. For fixed small angle sets, a lookup table can help, but prefer the library function until profiling proves otherwise.

Conclusion

sin() computes the sine of an angle in radians and returns a value between −1 and 1. Convert degrees before calling, pair it with cos() for circular motion, and remember it is not the same as sinh().

Continue with sinh() for hyperbolic math, or explore cos() for the horizontal component on the unit circle.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Convert degrees to radians before calling sin()
  • Use sinf / sinl when float precision is enough
  • Pair with cos() for 2D circular coordinates
  • Define _USE_MATH_DEFINES on MSVC for M_PI

❌ Don’t

  • Pass degrees directly to sin()
  • Confuse sin() with sinh()
  • Expect output outside [−1, 1]
  • Assume a built-in deg2rad exists in standard C
  • Reimplement sine unless profiling demands it

Key Takeaways

Knowledge Unlocked

Five things to remember about sin()

Trigonometric sine in C, explained simply.

5
Core concepts
📚 02

Range

[−1, 1].

Output
📈 03

Unit circle

y = sin(θ).

Geometry
📄 04

Odd fn

sin(−x)=−sin(x).

Property
🔄 05

vs sinh

Different.

Compare

❓ Frequently Asked Questions

sin() returns the sine of an angle given in radians. On a unit circle, sin(theta) is the y-coordinate at angle theta. For example, sin(0) is 0.0 and sin(pi/2) is 1.0 (90 degrees).
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double sin(double x).
Radians. Convert degrees first: radians = degrees * (M_PI / 180.0). Passing 60 directly to sin() is 60 radians, not 60 degrees.
The result is always between -1 and 1 inclusive. sin(0) is 0, sin(pi/2) is 1, and sin(3*pi/2) is -1.
sin() is a trigonometric sine (angles in radians, result in [-1, 1]). sinh() is the hyperbolic sine (uses exponential math, unbounded). They are different functions despite similar names.
Both take radians. sin(theta) gives the vertical (y) component on a unit circle; cos(theta) gives the horizontal (x) component. sin(pi/2) is 1 while cos(pi/2) is 0.
Did you know?

sin() is an odd function: sin(-x) equals -sin(x). That is why a sine wave is symmetric when flipped vertically—unlike cos(), which is even and unchanged for negative angles.

Explore C Math Functions

Continue with sinh() or browse the full math function reference.

Math Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful