Added the first problems for ProjectEuler.net

This commit is contained in:
2018-09-25 23:17:01 -04:00
parent 2f34971b55
commit 3fe2423e9a
3 changed files with 96 additions and 0 deletions

25
ProjectEuler/Problem1.m Normal file
View 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