English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Reference manual

C++ Biblioteca de Funções <cmath>

C ++cos() function usage and examples

This function returns the cosine value of the angle (parameter) expressed in radians in<cmath>defined in the header file.

[Mathematics] cos x = cos(x) [C++]

cos() prototype (from C ++ 11Standard beginning)

double cos(double x);
float cos(float x);
long double cos(long double x);
double cos(T x); //In this case, T is an integer type.

cos() parameter

cos() function takes a mandatory parameter in radians units.

cos() return value

cos() function returns[-1,1]returns the value within the specified range. The returned value is double, float or long double.

Exemplo1: how cos() in C ++working in C?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  double x = 0.5, result;
  
  result = cos(x);
  cout << "cos(x) = " << result << endl;
  
  double xDegrees = 25;
  
  //Convert degrees to radians
  x = xDegrees*3.14159/180;
  result = cos(x);
  
  cout << "cos(x) = " << result << endl;
  return 0;
}

A saída do programa será:

cos(x) = 0.877583
cos(x) = 0.906308

Exemplo2:função cos() com tipo inteiro

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int x = 1;
  double result;
  result = cos(x);
  cout << "cos(x) = " << result << endl;
  
  return 0;
}

A saída do programa será:

cos(x) = 0.540302

  C++ Biblioteca de Funções <cmath>