Computing the 10,005th Prime Number

조회 수: 2 (최근 30일)
Daniel Vehabovic
Daniel Vehabovic 2019년 2월 26일
답변: Naman Bhaia 2019년 3월 1일
Can someone please help me in regards to writing a script that will help you compute the 10,005th Prime Number.
These were some of the tips that were given to us to help us.
  • Use the MATLAB function isprime( ) to test if a number is prime.
  • You will want to use one variable to keep track of how many primes have been found (i.e. increment this value by one if a prime is found)
  • Use another variable to keep track of which value is being tested.
  • Use a while-loop to iterate until you have found 10,005 prime numbers.
  • Display the number that was being tested after the while loop is complete.
Any advice or help would be greatly apprecaited. I'm totally lost on this part.
  댓글 수: 1
James Tursa
James Tursa 2019년 2월 26일
You need to start writing some code and make an attempt. Then, when you have problems, come back with your code and ask specific questions about the issues you are having.

댓글을 달려면 로그인하십시오.

답변 (1개)

Naman Bhaia
Naman Bhaia 2019년 3월 1일
Hey Daniel,
What James said makes sense, you must try the problem and ask about your doubts here. But here are some hints to get the ball rolling.
  1. Initialise a count variable to 0
  2. Initialise a temporary variable to 2
  3. Run an infinite while loop
  4. Inside the loop, check if the temporary variable is prime. If yes, increase count by one
  5. Inside the loop, check if the count variable is equal to 10005. If yes, then break out from the loop
  6. End of while loop
  7. display the temporary variable as that contains the value of the prime number you need

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by