English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
وظائف المكتبة الخاصة بـ C++ <cmath>
يُرجع دالة hypot() في C++ الجذر التربيعي لجمع مربعات المعطيات المُتسلمين (حسب نظرية بيتاكسلوس).
double hypot(double x, double y); float hypot(float x, float y); long double hypot(long double x, long double y); مُعزز قوة (نوع1 x، نوع2 y); double hypot(double x, double y, double x); (من C++17) float hypot(float x, float y, float z); (من C++17) long double hypot(long double x, long double y, long double z); (من C++17) Promoted pow(Type1 x, Type2 y, Type2 y); (من C++17)
من C++ 11، إذا كان المعلمات المقدمة إلى hypot() نوع long double، فإن نوع العودة يُمكن تثبيته على long double. وإذا لم يكن كذلك، فإن نوع العودة يُمكن تثبيته على double.
h = √(x^2 + y^2
في الرياضيات، يساوي
h = hypot(x, y);
في برمجة C++.
إذا تم تقديم ثلاثة معلمات:
h = √(x^2 + y^2 + z^2))
في الرياضيات، يساوي
h = hypot(x, y);
في برمجة C++.
هذه الدالة تعمل في<cmath>محددة في ملف الرأس.
يمكن استخدام hytpot() مع 2 أو 3 معلمات من النوع integer أو float.
hypot() يعود:
إذا تم تقديم إثنين من المعلمات، فإنه يمثل ضلع الزاوية الحادة في مثلث قائم الزاوية، أي. √(x2+y2)
إذا تم تقديم ثلاثة معلمات، فإنه يمثل المسافة من النقطة الأصلية إلى (x،y،z). √(x2+y2+z2)
#include <iostream> #include <cmath> using namespace std; int main() { double x = 2.1, y = 3.1, result; result = hypot(x, y); cout << "hypot(x, y) = " << result << endl; long double yLD, resultLD; x = 3.52; yLD = 5.232342323; // في هذا المثال، يعود هذا الدالة نوع long double resultLD = hypot(x, yLD); cout << "hypot(x, yLD) = " << resultLD; return 0; {}
عند تشغيل هذا البرنامج، الناتج هو:
hypot(x, y) = 3.74433 hypot(x, yLD) = 6.30617
#include <iostream> #include <cmath> using namespace std; int main() { double x = 2.1, y = 3.1, z = 23.3, result; result = hypot(x, y, z); cout << "hypot(x, y, z) = " << result << endl; return 0; {}
ملاحظة:يشتغل هذا البرنامج فقط في محررات البرمجة التي تدعم C ++ 17.