Below is the implementation of finding prime factors of a whole number using MATLAB:
main.m470 chars18 lines
In this implementation, we are taking an input number from the user and initializing an empty array to store prime factors. We then loop over all numbers from 2 to the given number and keep dividing the input number by the current number until it is not divisible anymore. If the current number is a factor of the input number, we store it in the prime factors array. Finally we display the prime factors of the input number.
gistlibby LogSnag