mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-07 11:13:57 -05:00
22 lines
752 B
Matlab
22 lines
752 B
Matlab
%ProjectEuler/Problem4.m
|
|
%This is a script to answer Problem 4 for Project Euler
|
|
%Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
|
|
|
%Setup your variables
|
|
nums = [1:100];
|
|
squares = nums.^2; %Square every number in the list nums
|
|
sumOfSquares = sum(squares); %Get the sum of all the elements in the list squares
|
|
squareOfSums = sum(nums)^2; %Get the sum of all the elements in the list nums and square the answer
|
|
value = abs(squareOfSums - sumOfSquares); %Get the difference of the 2 numbers
|
|
%This could all be done on one line, but this is less confusing
|
|
|
|
%Print the value
|
|
value
|
|
|
|
%Cleanup your variables
|
|
clear nums;
|
|
clear squares;
|
|
clear sumOfSquares;
|
|
clear squareOfSums;
|
|
clear value;
|