91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

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

南部县| 曲松县| 偏关县| 阿勒泰市| 天水市| 道真| 东山县| 乐业县| 正宁县| 马龙县| 攀枝花市| 河池市| 枣阳市| 壶关县| 丹阳市| 阿克苏市| 江口县| 武夷山市| 新民市| 简阳市| 砀山县| 昭苏县| 高邮市| 治县。| 桓仁| 任丘市| 双流县| 乳源| 岳普湖县| 海门市| 平阳县| 泉州市| 许昌县| 南江县| 忻城县| 水富县| 鹰潭市| 伊金霍洛旗| 汝阳县| 双鸭山市| 和林格尔县|