Question

A3/3.1 Describe a non-recursive algorithm that takes a list of distinct integers a a, 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++, prime. Assume it is part of your You do not need to write a function to determine whether a number is language. E.g. For the list 3, 4, 5, 6, 7, your program should return 17 (because 2+3+5+7- 17 ospolntsy 2, procedure sum of primes (ai,az,..., an integers)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access...

    The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access to a global list of distinct integers a_1, a_2,..., a_n. procedure search(i, j, x : i,j, x integers, 1 < i < j < n) if a_i = x then return i else if i = j then 4. return 0 else return search(i + 1, j, x) Prove that this algorithm correctly solves the searching problem when called with parameters i = 1...

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • Hi please help with this program C++ language thanks Write a recursive solution to solve the...

    Hi please help with this program C++ language thanks Write a recursive solution to solve the Partition problem. Partition: Given a set A of n integers a, a, .....a., can you find a subset A_1 of integers such that the sum of the Integers in A_1 is half of the Sum of all the n Integers (that Is, sigma_alpha 1 A_1 a_i)? Input: 1.Number of integers of set A: n 2.n Integers: a_1 a_2, a_n. Output: Print out yes if...

  • 9. (5 points) Please describe an algorithm that takes as input a list of n integers...

    9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...

  • MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the...

    MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the greatest common divisor of two positive numbers. . • Your program should read the two positive integers using dialog boxes. If they are not positive, a message box should be displayed with an appropriate message. • Your program needs to have a procedure that takes two positive integers as parameters. • You need to follow cdecl protocol for parameter passing. • Display the valid...

  • MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the greatest...

    MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the greatest common divisor of two positive numbers. . • Your program should read the two positive integers using dialog boxes. If they are not positive, a message box should be displayed with an appropriate message. • Your program needs to have a procedure that takes two positive integers as parameters. • You need to follow cdecl protocol for parameter passing. • Display the valid...

  • Problem 3: (5 2 points) Design an algorithm that takes an array of positive integers A...

    Problem 3: (5 2 points) Design an algorithm that takes an array of positive integers A of length n and a positive integer T as an input and finds the largest N < T such that N can be written as a sum of some elements of A and returns such a representation of N. The complexity of the algorithms has to be O(nT). For example, for A 3,7, 10 and T 19, the output is 17 7+10, because we...

  • 8. Consider the following algorithm, which finds the sum of all of the integers in a...

    8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...

  • a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n...

    a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...

  • In this problem you will implement an algorithm for computing all the square roots of a congruenc...

    In this problem you will implement an algorithm for computing all the square roots of a congruence class in ℤ/nℤ, given a complete factorization of n into its distinct prime factor powers (assuming all the prime factors are in 3 + 4ℤ). a) Implement a Python function sqrtsPrime(a, p) that takes two arguments: an integer a and a prime number p. You may assume that a and p are coprime. If p is not in 3 + 4ℤ or a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT