C++ 中复数的 tan() 函数
在本文中,我们将讨论 C++ STL 中复数 tan() 函数的工作原理、语法和示例。
复数的 tan() 函数是 <complex> 头文件中的函数。此函数用于求与之关联的复数的正切值。此函数是 <cmath> 头文件中的简单 tan() 函数的复数版本。
什么是复数?
复数是实数和虚数的组合。
它们表示为:a+bi
其中 a 和 b 是实数,i 是虚数。
语法
template<class T> complex<T> tan (const complex<T>& num);
参数
此函数仅接受一个参数,即 num,它是一个复数值。
返回值
它返回 num 的正切值。
示例
Input: complex <double> num(0.0, 1.0); tan(num); Output: (0, 1.55741)
示例
#include <iostream>
#include <complex>
using namespace std;
int main () {
complex<double> tan_num(9.1, 2.6);
cout<<"tan of "<<tan_num<<" is "<<tan(tan_num);
return 0;
}输出
如果我们运行上述代码,它将生成以下输出:
tan of (9.1, 2.6) is (-0.00661488, 0.99123)
示例
#include <iostream>
#include <complex>
using namespace std;
int main () {
complex<double> tan_num(1.0, 0.0);
cout<<"tan of "<<tan_num<<" is "<<tan(tan_num);
return 0;
}输出
如果我们运行上述代码,它将生成以下输出:
tan of (1, 0) is (1.55741, 0)
广告宣传
数据结构
计算机网络
关系型数据库
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP