A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

So I am on ps1pr2. Through reading here, I figured out the first problem and here is my code. I tweaked it a little to fit the second problem and let the user input to what prime is being calculated: http://codepad.org/ALTEQij0 My next question is what should my next step be? I am at a bit of a loss as how to calculate the sums of the logs. Should I assign a new variable (sumoflog), and then just keep adding to that as I work through the prime numbers?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry, I used "answer" as a variable in my additional code that lets the user put in a number. Makes is a little confusing. thats better: http://codepad.org/o98NeR9d

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes. Start a new variable at the beginning of your program that will keep track of the sum of the logs of the prime numbers. Since you assume that 3 is already a prime number, you should set the variable initially as: sumoflog=log(3) as you cycle through the primes sumoflog should increase sumoflog=log(3)+log(5)+log(7)... you will use a statement such as sumoflog+=log(n) where n is a number that you have determined is a prime

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the heads up malpaso. As I was writing my question it began to make more sense, but your additional explanation will really help me out.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I misread your program. You assume that 2 is a prime and test for 3. So initially you would set: sumoflog=log(2)

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Cool. Thanks!

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Got it cleared up. Any suggestions welcome: http://codepad.org/QGEu30fc

  7. maitre_kaio
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    You could improve the readability by changing the lines: if divisor<(number) if divisor>=(number) with the structure if ... else Otherwise good job

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks Maitre

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.