Borrar filtros
Borrar filtros

For loop comand use

1 visualización (últimos 30 días)
F.O
F.O el 5 de Oct. de 2017
Comentada: F.O el 6 de Oct. de 2017
Hi,I want to compute the sum 2 + 4 + 6 + 8 + 10 + : : : + 100 by using For loop . Can anyone here thankfully help me out?
  4 comentarios
James Tursa
James Tursa el 5 de Oct. de 2017
Editada: James Tursa el 5 de Oct. de 2017
Change
total = total + 1;
to
total = total + k; % <-- You need to add the index variable k, not 1 every time
F.O
F.O el 6 de Oct. de 2017
I have changed it and got correct answer. Thanks

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 5 de Oct. de 2017
The general outline of your for loop would be:
total = 0;
for k=start_value:increment:end_value % <-- you fill in the start_value, increment, and end_value
total = total + something; % <-- you fill in the something
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by