Example 1 — Basic Cosine Values
Use a portable pi from acos(-1.0) and print a few known results.
#include <stdio.h>
#include <math.h>
int main(void) {
double pi = acos(-1.0);
printf("cos(0) = %.6f\n", cos(0.0));
printf("cos(pi/3) = %.6f\n", cos(pi / 3.0));
printf("cos(pi) = %.6f\n", cos(pi));
return 0;
} How It Works
- Build pi.
acos(-1.0)is a portable way to get π. - cos(0) is 1. Angle zero points along the positive x-axis.
- cos(π/3) is 0.5. That is the classic 60° cosine.
- cos(π) is -1. A half turn points left on the unit circle.

