中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C++ math庫函數測試方法

發布時間:2024-11-18 13:29:17 來源:億速云 閱讀:78 作者:小樊 欄目:編程語言

在C++中,我們可以使用<cmath>庫來進行數學運算

  1. 測試平方根函數:
#include <iostream>
#include <cmath>

int main() {
    double number = 9.0;
    double squareRoot = sqrt(number);
    std::cout << "The square root of " << number << " is: " << squareRoot << std::endl;
    return 0;
}
  1. 測試冪函數:
#include <iostream>
#include <cmath>

int main() {
    double base = 2.0;
    double exponent = 3.0;
    double power = pow(base, exponent);
    std::cout << "The power of " << base << " to the " << exponent << " is: " << power << std::endl;
    return 0;
}
  1. 測試三角函數:
#include <iostream>
#include <cmath>

int main() {
    double angleInRadians = M_PI / 4; // 45 degrees in radians
    double sineValue = sin(angleInRadians);
    double cosineValue = cos(angleInRadians);
    double tangentValue = tan(angleInRadians);

    std::cout << "The sine of " << angleInRadians << " radians is: " << sineValue << std::endl;
    std::cout << "The cosine of " << angleInRadians << " radians is: " << cosineValue << std::endl;
    std::cout << "The tangent of " << angleInRadians << " radians is: " << tangentValue << std::endl;
    return 0;
}
  1. 測試指數和對數函數:
#include <iostream>
#include <cmath>

int main() {
    double number = 2.0;
    double exponent = 3.0;
    double result = pow(number, exponent);
    std::cout << "The result of " << number << " raised to the power of " << exponent << " is: " << result << std::endl;

    double logarithmBase = 2.0;
    double logarithmValue = log(number) / log(logarithmBase);
    std::cout << "The logarithm of " << number << " to the base of " << logarithmBase << " is: " << logarithmValue << std::endl;
    return 0;
}
  1. 測試取整函數:
#include <iostream>
#include <cmath>
#include <limits>

int main() {
    double number = 4.7;
    int integerPart = static_cast<int>(number);
    double fractionalPart = number - integerPart;

    std::cout << "The integer part of " << number << " is: " << integerPart << std::endl;
    std::cout << "The fractional part of " << number << " is: " << fractionalPart << std::endl;

    int ceilingValue = ceil(number);
    int floorValue = floor(number);

    std::cout << "The ceiling value of " << number << " is: " << ceilingValue << std::endl;
    std::cout << "The floor value of " << number << " is: " << floorValue << std::endl;

    return 0;
}

這些測試示例展示了如何使用C++的<cmath>庫進行基本的數學運算。在實際應用中,你可能需要根據具體需求對這些函數進行調整和擴展。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

c++
AI

喀喇沁旗| 宿迁市| 扶余县| 东乡族自治县| 衢州市| 新丰县| 常德市| 恭城| 临湘市| 新宁县| 莎车县| 罗定市| 敖汉旗| 汶川县| 武川县| 安宁市| 保德县| 宜昌市| 庆城县| 黔西| 怀远县| 平远县| 平罗县| 定兴县| 同德县| 额尔古纳市| 华容县| 江孜县| 安多县| 五原县| 洞口县| 遂昌县| 桃源县| 塘沽区| 乐陵市| 水城县| 桐城市| 汝南县| 洞头县| 行唐县| 广西|