Exercises

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

  1. Write a program script that accepts an integer, stores it in a variable, and outputs a vector of the prime factors of the integer if it is a positive integer. If the integer is negative, display a message to the user that the integer must be positive.

        value = input('Enter an integer: ');
        if ( value > 0 ) 
    	    factors = factor(value);
            disp( ['The prime factors of ',num2str(value),' are ', num2str(factors)]);
        else
            disp( 'The integer must be positive.' );
        end
    

    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.