perimeter , area of circle

7 vues (au cours des 30 derniers jours)
Minh
Minh le 30 Sep 2022
Commenté : Minh le 30 Sep 2022
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);

Réponse acceptée

Davide Masiello
Davide Masiello le 30 Sep 2022
Modifié(e) : Davide Masiello le 30 Sep 2022
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 commentaire
Minh
Minh le 30 Sep 2022
@Davide Masiello thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by