กำหนดให้เป็นงานในการค้นหาการทำงานของฟังก์ชัน sqrt() สำหรับจำนวนเชิงซ้อน โดยทั่วไป sqrt( ) เป็นฟังก์ชันที่มีอยู่ในไฟล์ส่วนหัวที่ซับซ้อน ฟังก์ชันนี้ใช้ในการคำนวณรากที่สองของจำนวนเชิงซ้อน
ไวยากรณ์
template<class t> complex<t> Sqrt(const complex<t>& x);
พารามิเตอร์
x - พารามิเตอร์นี้ x ซึ่งแทนจำนวนเชิงซ้อน
ผลตอบแทนที่ได้รับ
ฟังก์ชันนี้จะคืนค่ารากที่สองของจำนวนเชิงซ้อน
อินพุต − Sqrt(3,8i)
ผลผลิต − (2.4024,1.6649)
ป้อนข้อมูล Sqrt(7,1i)
ผลผลิต − (2.6524,0.1885)
ตัวอย่าง
#include<iostream.h>
#include<complex.h>
Using namespace std;
int main( ){
/ / Defining of complex Number
Complex<double> x(4,9);
Cout<< “ The square root of “ << x << “ = “ << sqrt(x) << endl;
Return 0;
} ผลลัพธ์
หากเรารันโค้ดด้านบน มันจะสร้างผลลัพธ์ต่อไปนี้
The square root of (4,9) = (2.631,1.710)
ตัวอย่าง
#include<iostream.h>
#include<complex.h>
Using namespace std;
int main( ){
/ / defining the complex Number
Complex<double> x(2, 6);
Cout<< “ The square root of “ << x << “ = “ << sqrt(x) << endl;
return 0;
} ผลลัพธ์
หากเรารันโค้ดด้านบน มันจะสร้างผลลัพธ์ต่อไปนี้
The square root of (2,6) = (2.0401,1.4704)