]> Exercises

Exercises

Please complete each exercise or answer the question before reviewing the posted solution comments.

Use the clear command before starting your work on a new problem to ensure that any existing variable name assignments don't interfere with your work on the new problem.

  1. Write a code fragment that accepts a positive integer, stores it in a variable, and then outputs a vector of the prime factors of the integer.

    Hint: search the online help for a function that will return the factors of an integer. Also, your code fragment does not have to test the input value for negative values or non-integer values. The next lesson will introduce this topic.

        value = input('Enter a positive integer: ');
        factors = factor(value)
    

    The factor() function returns a vector containing the prime factors of N. An error occurs, if a negative value or a non-integer is entered.