C ++ hipotēka () - C ++ standarta bibliotēka

Funkcija Hipotēka () C ++ atgriež pieņemto argumentu kvadrāta saknes kvadrātsakni.

hipot () prototips

dubultā hipota (dubultā x, dubultā y); pludiņš hipots (pludiņš x, pludiņš y); garš dubults hipots (garš dubultā x, garš dubultā y); Paaugstinātā vara (Type1 x, Type2 y); dubultā hipota (dubultā x, dubultā y, dubultā x); // (kopš C ++ 17) peldošs hipots (pludiņš x, pludiņš y, pludiņš z); // (kopš C ++ 17) garš dubults hipots (garš dubultā x, garš dubultā y, garš dubultā z); // (kopš C ++ 17) Reklamētā vara (Type1 x, Type2 y, Type2 y); // (kopš C ++ 17)

Kopš C ++ 11, ja kāds hipotam () nodots arguments ir long double, atgriešanās tips Promoted ir long double. Ja nē, atgriešanās veids ir Promoted double.

 h = √ (x2 + y2

matemātikā ir ekvivalents

 h = hipots (x, y);

C ++ programmēšanā.

Ja tiek nodoti trīs argumenti:

 h = √ (x2 + y2 + z2))

matemātikā ir ekvivalents

 h = hipots (x, y);

C ++ programmēšanā.

Šī funkcija ir definēta galvenes failā.

hipot () parametri

Hytpot () ņem 2 vai 3 integrālā vai peldošā komata parametrus.

hipot () Atgriešanās vērtība

Hipotēka () atgriež:

  • taisnleņķa trijstūra hipotenūza, ja tiek nodoti divi argumenti, ti .√(x2+y2)
  • attālums no sākuma līdz punktam (x, y, x), ja tiek nodoti trīs argumenti, ti ,.√(x2+y2+z2)

1. piemērs: Kā hipot () darbojas C ++?

 #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; ) 

Palaidot programmu, izeja būs:

 hipots (x, y) = 3,74433 hipots (x, yLD) = 6,30617 

2. piemērs: hipotēka () ar trim argumentiem

 #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; )

Piezīme: Šī programma darbosies tikai jaunos kompilatoros, kas atbalsta C ++ 17.

Interesanti raksti...