Question
Maple a) Write a procedure, primesum, whose input is a positive integer n and whose output is the sum of all primes p such that
Maple a) Write a procedure, primesum, whose input is a positive integer n and whose output is the sum of all primes p such that p <= n. You may use the built-in procedure isprime. Test the procedure for n= 2, 4, 10, and 1000.
primesum:=proc(n) local SUM, k; SUM:=0; for k from 1 to n do if isprime(k)=true then SUM:=SUM + k; end if; end do; end proc: primesum(12);
I did this but no result comes out when the number input is not prime. How do I fix this? I have the same problem with the next one.
b) Write a procedure, primeset, whose input is a positive integer n and whose output is the set of all primes p such that p <= n. You may use the built-in procedure isprime. Test the procedure for n = 2, 4, 10, and 1000.b) Write a procedure, primeset, whose input is a positive integer n and whose output is the set of all primes p such that p <= n. You may use the built-in procedure isprime. Test the procedure for n = 2, 4, 10, and 1000.
primeset:=proc(n) local SUM, S,k; S:={}; for k from 1 to n do if isprime(n)=true then S:=S union {k}; end if; end do; end proc: primeset(5);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started