Ads by ProfitSence

C++ tan()

Last Updated on Wednesday 5th Oct 2022

The C++ tan() function returns the tangent of an angle in radians. It is defined in <cmath> header file.





The tan() function takes a one argument. It can be positive, negative, or zero.

Return value

The tan() function returns the value in the range of [-∞, ∞].

tan() prototype [As of C++ 11 standard]

					double tan(double x);
float tan(float x);
long double tan(long double x);
double tan (T x); // For integral type


Example 1: C++ atan()

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

#define PI 3.14159265

int main () {
  double param, result;
  param = 22.0;
  result = tan(param * PI / 180.0);
  printf ("The tangent of %f degrees is %f.\n", param, result );
  return 0;



					The tangent of 22.000000 degrees is 0.404026.


Example 2 : C++ tan() with integral type

					#include <iostream>
#include <cmath>
using namespace std;

int main() {
  long int x = 8;
  double result;

  result = tan(x);
  cout << "tan(x) = " << result;

  return 0;



					tan(x) = -6.79971