Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab Programming help! Please provide working code that I can copy and paste f

ID: 2082683 • Letter: M

Question

Matlab Programming help! Please provide working code that I can copy and paste for following question.

A perfect number is a positive integer that is equal to the sum of its positive divisors including 1 but excluding the number itself. The first perfect number is 6 = 1 + 2 + 3, the next perfect number is 28 = 1 + 2 + 4 + 7 + 14. Write a program that finds perfect numbers and stores them in the array P until the multiplication of them exceeds a given integer N. Organize your program into a main script and a function (named "isperfect") determining whether or not an integer is perfect. You are allowed to use the functions 'sum' and 'rem'.

Explanation / Answer

Matlab code:

clc;
clear all;
n = 3;
i = 1;
while(n > 0)
sum = 0;
for j = 1:i-1
if(mod(i,j) == 0)
sum = sum + j;
end
end
if(i == sum)
fprintf('%d is a perfect number ',i);
n =n-1;
end
i = i+1;
end

Result will be shown as

6 is a perfect number

28 is a perfect number

496 is a perfect number