By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
Write a program to take a positive number n as an input and find the nth prime number. For example, if the user enters 20, the output should be 71 (20th prime number).
Marking Scheme
Writing down how your program will solve the task
Pseudo code
C# code
Indentation in the code
Comments in the code
Presentation
1
Expert's answer
2014-07-24T08:45:34-0400
using System;
public class Test { publicstatic void Main() { Console.WriteLine(getPrimeForNumber(12)); } publicstatic bool isPrime(int number){ for(int i=2;i<=number/2;i++){ if(number%i==0){ returnfalse; } } returntrue; } publicstatic int getPrimeForNumber(int number){ inti=1; intcounter = 0; while(counter<number){ i++; if(isPrime(i)){ counter++;
}
} returni; } }
Pseudocode: Input number Go through all numbers If prime then increment counter If counter equal to user input, thenoutput result
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment