perimeter , area of circle

13 ビュー (過去 30 日間)
Minh
Minh 2022 年 9 月 30 日
コメント済み: Minh 2022 年 9 月 30 日
I am doing a code to calculate the circumference and area of a circle, but when I get the results, the answer is the circumference and area are reversed, I don't know where I am wrong?
r = input('r= ');
P = pi * 2 * r;
S = pi * (r^2);
fprintf('P = %.2f\n',S);
fprintf('S = %.2f\n',P);

採用された回答

Davide Masiello
Davide Masiello 2022 年 9 月 30 日
編集済み: Davide Masiello 2022 年 9 月 30 日
You just need to change the arguments in fprintf, since you must have accidentally swapped them.
r = 1;
P = pi * 2 * r;
S = pi * (r^2);
fprintf('P = %.2f\n',P);
P = 6.28
fprintf('S = %.2f\n',S);
S = 3.14
  1 件のコメント
Minh
Minh 2022 年 9 月 30 日
@Davide Masiello thank you very much

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by