Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ฟังก์ชัน log10() สำหรับจำนวนเชิงซ้อนใน C++

ในบทความนี้ เราจะพูดถึงการทำงาน ไวยากรณ์ และตัวอย่างของฟังก์ชัน log10() ใน C++ STL

log10() Function คืออะไร?

log10() เป็นฟังก์ชันในตัวของ C++ STL อยู่ใน header <complex> ใช้หาค่า common logarithmic (ฐาน 10) ของจำนวนเชิงซ้อน

ไวยากรณ์

template<class T> complex<T> log10(const complex<T>& num);

พารามิเตอร์

ฟังก์ชันรับพารามิเตอร์ 1 ตัว คือ num ชนิด complex value ที่ต้องการหา log

ค่าที่คืน

คืนค่า common complex log value ฐาน 10 ของ num

ตัวอย่าง

Input: complex<double> C_number(-4.0, -1.0); log10(C_number); Output: log10 of (-4,-1) is (0.615224,-1.25798)

ตัวอย่างโค้ด 1

#include <bits/stdc++.h>
using namespace std;

int main() {
    complex<double> C_number(-4.0, -1.0);
    cout << "log10 of " << C_number << " is " << log10(C_number);
    return 0;
}

เอาต์พุต

log10 of (-4,-1) is (0.615224,-1.25798)

ตัวอย่างโค้ด 2

#include <bits/stdc++.h>
using namespace std;

int main() {
    complex<double> C_number(-4.0, 1.0);
    cout << "log10 of " << C_number << " is " << log10(C_number);
    return 0;
}

เอาต์พุต

log10 of (-4,1) is (0.615224,1.25798)