fork download
  1. #include <stdio.h>
  2. #include<math.h>
  3.  
  4. int is_prime(int n){
  5. for (int i = 2; i <= sqrt(n); ++i)
  6. if((n%i) ==0)
  7. return 0;
  8. return 1;
  9. }
  10. int nth_prime(int n){
  11. int c=2;
  12. int i=0;
  13. while(i<n)
  14. {
  15. if(is_prime(c))
  16. ++i;
  17. ++c;
  18. }
  19. return c-1;
  20. }
  21. int main(int argc, char const *argv[])
  22. {
  23. int n;
  24. printf("please give a value for n");
  25. scanf("%d",&n);
  26. printf("the %dth prime is: %d",n,nth_prime(n));
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
please give a value for nthe 5232th prime is: 51133