-1

教えてくれるmatlab内の関数をコンパイルしています

  1. 三角形の 3 番目の辺
  2. 三角形の周囲の長さ
  3. 三角形の面積

私はこれまでにこれを思いついた

function findHypotenuse(a, b)
    c=sqrt(a^2+b^2);
    circumference = (a+b+c);
    area = (.5*(a*b));
    fprintf('Triangle has side c which is %g.\n',c)
    fprintf('Triangle has a circumference of %g.\n',circumference)
    fprintf('Triangle has area of %g.\n',area)
    fprintf('Triangle has area of %g.\n',area)

その結果、コマンドウィンドウに入れると、このようなものが得られます

   >> findHypotenuse(6,8)
      Triangle has side c which is 10.
      Triangle has a circumference of 24.
      Triangle has area of 24.
      Triangle has area of 24.

「a Triangle with side _ and side _ has side c which c」の行に沿って何かを言う方法と、見つかった他の2つのものと同じ形式を理解するのに助けが必要です。

また*三角形が二等辺三角形である場合にイエスかノーかを教えてくれる関数をコンパイルしたい

4

1 に答える 1

1

fprintf('A triangle with sides %.1f and %.1f has a hypotenuse of %.1f and a circumference of %.1f\n', a, b, c, a+b+c);

必要なもののようです。数値を別の方法でフォーマットできるようにしたい場合は、非常に賢くなり、追加することができます

fs = '%.3f';
fprintf(['A triangle with sides ' fs ' and ' fs ' has a hypotenuse of %.1f and a circumference of %.1f\n], a, b, c, a+b+c);

これにより、回答の精度を変更でき、すべての数値の書式設定が同じ方法で変更されます。

于 2013-01-11T22:52:30.593 に答える