fprintf for total sum

11 vues (au cours des 30 derniers jours)
fushen Lee
fushen Lee le 7 Fév 2021
Commenté : fushen Lee le 7 Fév 2021
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 commentaires
Walter Roberson
Walter Roberson le 7 Fév 2021
Rewriting in terms of index looks better.
fushen Lee
fushen Lee le 7 Fév 2021
Hi Roberson,
Thank you for you advice i was able to get the result after rewrite.

Connectez-vous pour commenter.

Réponse acceptée

Ive J
Ive J le 7 Fév 2021
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 commentaire
fushen Lee
fushen Lee le 7 Fév 2021
Thank you so much J.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by