Exercise: Get nth Prime Number

Write code to solve the problem.

Question

Write a program that takes a positive integer n as an input returns the nth prime number. If the input is not a positive integer, it returns 0.

Sample input:

getNthPrime(1)
getNthPrime(3)
getNthPrime(1000)

Sample output:

2
5
7919

Exercise: Get nth Prime Number

Write code to solve the problem.

Question

Write a program that takes a positive integer n as an input returns the nth prime number. If the input is not a positive integer, it returns 0.

Sample input:

getNthPrime(1)
getNthPrime(3)
getNthPrime(1000)

Sample output:

2
5
7919
C
#include <stdio.h>
int getNthPrime(int n)
{
// Write your code here...
return 0;
}
int main(void)
{
int n = 10;
printf("%dth prime number is %d\n", n, getNthPrime(n));
return 0;
}