%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); ans = fullSum %Cleanup your variables clear fullSum; clear numbers; clear counter;