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 comentarios

Walter Roberson
Walter Roberson el 7 de Feb. de 2021
Caution: you are not changing i within the loop, so every iteration is going to be adding exactly the same thing to the total.
fushen Lee
fushen Lee el 7 de Feb. de 2021
hi Roberson,
I just did some edit on the script dose it correct?
when i run on display i able to get the total , when i try on fprintf it not working.
Walter Roberson
Walter Roberson el 7 de Feb. de 2021
Rewriting in terms of index looks better.
fushen Lee
fushen Lee el 7 de Feb. de 2021
Hi Roberson,
Thank you for you advice i was able to get the result after rewrite.

Iniciar sesión para comentar.

 Respuesta aceptada

Ive J
Ive J el 7 de Feb. de 2021

0 votos

doc fprintf
An example for a floating point number:
X = 2.345674;
fprintf('My number is %.2f\n', X)
My number is 2.35

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Feb. de 2021

Comentada:

el 7 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by