Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the second picture is the code that needs to be edited 1 The script EGA118_M2_01.m attempts to calculate the sum of the first n prime

the second picture is the code that needs to be edited
image text in transcribed
image text in transcribed
1 The script EGA118_M2_01.m attempts to calculate the sum of the first n prime numbers. Note that 2 is the first prime and the sum of the first seven primes is 58. There are a small number of minor errors in the script that you need to correct. No lines need to be added to the script to make it run correctly. You only need to adjust some of the exiting lines. Having corrected the existing script you should change the script so that the user is asked to provide a value for n. (10 marks clear % This scripts attempts to find the sum of the first n primes i=1; prime_count=0; sum = 0; n=7; while prime_count can if -isprime(1) % isprime returns TRUE if i is a prime prime_count = prime_count + 1; sun = sum + 1; end i = i + 1; end fprintf('The sum of the first %d primes is %d ', n, sum)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

Students also viewed these Databases questions