Finding all multiples of 5 or 7 from 1 to 10000 with a loop.
6 views (last 30 days)
Show older comments
Thanks! I just got it
0 Comments
Answers (1)
James Tursa
on 30 Jan 2020
An basic outline of the for loop to get you started:
n = 10000; % the limit of the for loop
x57a = []; % initialize the result to an empty vector using the specified variable name
for k=1:n % the for-loop to process the numbers
if( k is divisible by 5 or 7 but not both ) % <-- You write this code
x57a(end+1) = k; % append k to the result vector
end
end
You need to write the code for the logic in the if-test. For the code you write, you can use the mod( ) or rem( ) function to see if a number is exactly divisible by another number.
doc mod
doc rem
0 Comments
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!