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

Devise algorithms to solve each of the following problems. Write each algorithm

ID: 3877850 • Letter: D

Question

Devise algorithms to solve each of the following problems. Write each algorithm in pseudocode

Given a list, L, of integers greater than or equal to 1, return a new list containing just the prime numbers from L. Numbers can appear in this output in whatever order you like, it doesn’t need to be the same order in which they appeared in L. You may make the length of L an input to your algorithm, or assume there is a primitive operation for finding it. However, do not assume that testing for primality is a primitive operation

Explanation / Answer

DESCRIPTION

The function has one parameter it accepts the list through it.The main loop interated to its length and each of the number is checked for prime numbers.If it is a prime number then the number is added to the new list and if is not it just continue with the checking.

Algorithim

check_prime(list l)

{

for (i=1 to length of the list)

{

k=list[i];

for(i=1 to k)

{

if(k mod i is 0)

c=c+1;

}

if(c==2)

new_list[m++]=c;

}

}

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