Can someone give an example of a for loop for this problem?: Find the sum of 30 numbers that increments by 3. The starting number is 4. Thanks!
1 view (last 30 days)
Show older comments
Just a simple for loop please. Nothing too complicated. Thank you again.
2 Comments
Steven Lord
on 7 Dec 2018
In general if you post a question like this that sounds like a homework assignment, even if it isn't a homework assignment, I recommend posting what you've tried and asking for help improving and/or fixing it. The problem might be as simple as a typo in your code, and seeing that code may allow someone to respond within seconds with the easy fix.
From your question itself, I'm guessing you're fairly new to MATLAB. If that's right, consider going through the free MATLAB Onramp course in the Tutorial section on the Support page if you haven't already. [Click Support in the bar at the top of this page.] It will teach you some of the basics of MATLAB and perhaps fill in any gaps in what you've learned so far.
Accepted Answer
Sean de Wolski
on 7 Dec 2018
x = sum(4:3:(4+3*(30-1)))
8 Comments
John D'Errico
on 10 Dec 2018
Edited: John D'Errico
on 10 Dec 2018
@Madhan - don't worry about upvotes anyway. Reputation is not important, and there is no race to the top. Your responses are appreciated, improving the site with your presence, regardless of an upvote or not..
More Answers (1)
madhan ravi
on 7 Dec 2018
Read about sum() and cumsum() loops are superfluous in this case
9 Comments
madhan ravi
on 7 Dec 2018
Yes I just saw your comment in your previous question @TSmith , Best of luck!
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!