Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Describe a non-recursive algorithm that takes a list of distinct integers a_1, a

ID: 3811679 • Letter: D

Question

Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and finds the sum of the primes in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C++, ..... You do not need to write a function to determine whether a number is prime. Assume it is part of your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 17 (because 2 + 3 + 5 + 7 = 17) procedure Sum_of_primes (a_1, a_2, ..., a_n: integers)

Explanation / Answer

procedure Sum_of_primes(a1,a2,.........an:integers)
start
s=0
for each ai where i=1 to n
   if(isprime(ai))
       s = s + ai
   end if
end for
output s
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote