# Math Help - matlab code helpppp :(

1. ## matlab code helpppp :(

helpp!! i need a MATLAB CODE!

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

i need the matlab code for this it is so confusing i got other codes but they do not seem to be working

2. Originally Posted by savni98
helpp!! i need a MATLAB CODE!

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

i need the matlab code for this it is so confusing i got other codes but they do not seem to be working
First decide what algorithm you are going to employ, then post it here and explain what it is with the algorithm you are having trouble turning into code.

CB

3. i got some of the code i think i dont know what to do ??

for i = 20:2:1000000000
t = 0;
for j = 2:20
t += 1
end
end
if t == 19

without the code it goes

20=2*2*5
19
18=2*3*3
17
16=2*2*2*2
15=3*5
14=2*7
13
12=2*6
11
10=2*5
9=3*3
8=2*2*2
7
6=2*3
5
4=2*2
3
2
1

2*2*2*2*3*3*5*7*11*13*17*19=232,792,56

4. Originally Posted by savni98
i got some of the code i think i dont know what to do ??

for i = 20:2:1000000000
t = 0;
for j = 2:20
t += 1
end
end
if t == 19

without the code it goes

20=2*2*5
19
18=2*3*3
17
16=2*2*2*2
15=3*5
14=2*7
13
12=2*6
11
10=2*5
9=3*3
8=2*2*2
7
6=2*3
5
4=2*2
3
2
1

2*2*2*2*3*3*5*7*11*13*17*19=232,792,56
Start with p=20, then loop from n= 19 down to 1 with update p=lcm(n,p)

so the core code would look something like:

Code:
p=20
n=19:-1:1
p=lcm(p,n);
end
CB