perimeter , area of circle
조회 수: 6 (최근 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);
댓글 수: 0
채택된 답변
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);
fprintf('S = %.2f\n',S);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!