C ++ 'daki hipot () işlevi, iletilen argümanların karelerinin toplamının karekökünü döndürür.
hipot () prototip
çift hipot (çift x, çift y); float hipot (float x, float y); uzun çift hipot (uzun çift x, uzun çift y); Promoted pow (Type1 x, Type2 y); çift hipot (çift x, çift y, çift x); // (C ++ 17'den beri) float hipot (float x, float y, float z); // (C ++ 17'den beri) uzun çift hipot (uzun çift x, uzun çift y, uzun çift z); // (C ++ 17'den beri) Yükseltilmiş pow (Type1 x, Type2 y, Type2 y); // (C ++ 17'den beri)
C ++ 11'den beri, hipot () 'a iletilen herhangi bir argüman varsa long double
, dönüş türü Promoted'dir long double
. Değilse, Promoted dönüş türü double
.
h = √ (x2 + y2
matematikte eşdeğerdir
h = hipot (x, y);
C ++ Programlamada.
Üç argüman iletilirse:
h = √ (x2 + y2 + z2))
matematikte eşdeğerdir
h = hipot (x, y);
C ++ Programlamada.
Bu işlev başlık dosyasında tanımlanmıştır.
hypot () Parametreler
Hytpot (), 2 veya 3 integral veya kayan nokta tipi parametre alır.
hypot () Dönüş Değeri
Hipot () şunu döndürür:
- iki argüman iletilirse dik üçgenin hipotenüsü, yani .
√(x2+y2)
- Üç argüman iletilirse, orijinden (x, y, x) 'e olan mesafe, yani .
√(x2+y2+z2)
Örnek 1: hypot () C ++ 'da nasıl çalışır?
#include #include 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; // hypot() returns long double in this case resultLD = hypot(x, yLD); cout << "hypot(x, yLD) = " << resultLD; return 0; )
Programı çalıştırdığınızda, çıktı:
hipot (x, y) = 3,74433 hipot (x, yLD) = 6,30617
Örnek 2: Üç Bağımsız Değişken ile hipot ()
#include #include 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; )
Not: Bu program yalnızca C ++ 17'yi destekleyen yeni derleyicilerde çalışacaktır.