Question: The output should have 5 numbers per line separated by commas. After the function has displayed all n values, only one new line should be

The
output should have 5 numbers per line separated by commas.
After the function has displayed all n values, only one new line
should be at the end of the list of numbers. Display the CPU
time required to run the function on a new line after it has
printed out all of the prime numbers.
function []=disp_prime(n)
% This function is the starting point for the disp_prime bonus
% assignment. Your task is to modify this code so it will run
% faster. Your bonus will be determined by how much faster your
% code runs in comparison to this code.
% The input value n is the number of prime numbers to display.
% There is no function output but the code displays prime
% numbers in the command window.
tic; c=0; v=2; % Initialize values
if n1 disp('No primes'); % Check for valid input
else
if n>=1 fprintf('2,'); c=1; end
if n>=2 fprintf('3,'); c=2; end
if n>=3 v=5;
while c
The output should have 5 numbers per line

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!