mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added the first problems for ProjectEuler.net
This commit is contained in:
25
ProjectEuler/Problem1.m
Normal file
25
ProjectEuler/Problem1.m
Normal file
@@ -0,0 +1,25 @@
|
||||
%ProjectEuler/Problem1.m
|
||||
%This is a script to answer Problem 1 for Project Euler
|
||||
%What is the sum of all the multiples of 3 or 5 that are less than 1000
|
||||
|
||||
%Setup your variables
|
||||
fullSum = 0; %To hold the sum of all the numbers
|
||||
numbers = 0; %To hold all of the numbers
|
||||
counter = 0; %The number. It must stay below 1000
|
||||
|
||||
while(counter < 1000)
|
||||
%See if the number is a multiple of 3
|
||||
if(mod(counter, 3) == 0)
|
||||
numbers(end + 1) = counter;
|
||||
%See if the number is a multiple of 5
|
||||
elseif(mod(counter, 5) == 0)
|
||||
numbers(end + 1) = counter;
|
||||
end
|
||||
|
||||
%Increment the number
|
||||
++counter;
|
||||
end
|
||||
%When done this way it removes the possibility of duplicate numbers
|
||||
|
||||
fullSum = sum(numbers);
|
||||
fullSum
|
||||
Reference in New Issue
Block a user