fprintf for total sum

조회 수: 3 (최근 30일)
fushen Lee
fushen Lee 2021년 2월 7일
댓글: fushen Lee 2021년 2월 7일
N = input("Enter value for N:");
total = 0;
for index=1:N
total = total +(1/index+1/((index+2)*(index+3))) ;
end
fprintf(
Question how to it fprintf the answer, i able to use display but i have not idea how to made it on fprintf?
  댓글 수: 4
Walter Roberson
Walter Roberson 2021년 2월 7일
Rewriting in terms of index looks better.
fushen Lee
fushen Lee 2021년 2월 7일
Hi Roberson,
Thank you for you advice i was able to get the result after rewrite.

댓글을 달려면 로그인하십시오.

채택된 답변

Ive J
Ive J 2021년 2월 7일
doc fprintf
An example for a floating point number:
X = 2.345674;
fprintf('My number is %.2f\n', X)
My number is 2.35
  댓글 수: 1
fushen Lee
fushen Lee 2021년 2월 7일
Thank you so much J.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by