😸

[C] hypot 関数

に公開

機能

2つの値の直角三角形の斜辺の長さ(平方根の和)を計算する[1]

使用例

5.000000 と表示する

\n は改行を表す エスケープシーケンス[2]

コード

printf("%f\n", hypot(3.0, 4.0));
全文
#include <stdio.h>
#include <math.h>
void main() {
    printf("%f\n", hypot(3.0, 4.0));
}

実行結果

5.000000

10.816654 を変数から表示する

コード

double x = 6.5, y = 8.5;
printf("%f\n", hypot(x, y));
全文
#include <stdio.h>
#include <math.h>
void main() {
    double x = 6.5, y = 8.5;
    printf("%f\n", hypot(x, y));
}

実行結果

10.816654
脚注
  1. hypotは「√(x² + y²)」を安全に計算する関数。オーバーフローやアンダーフローを防ぐために使われる。 ↩︎

  2. 改行やタブなど、画面に表示されない制御文字のこと。 ↩︎

Discussion