My questions are how to find the nth prime number?
I have figured out how to find a list prime numbers.
I'm just stuck as for being able to change my code to
only print out the, say, 15th, or 500th prime not
every previous prime as well.
Any help/feed back would be great!!
thanks

#include<stdio>

 main()
 {
    int primenumber;
    int num;
    int count;
    int x;
    num = 3;


    printf("Prime number interested in finding a value for?\n");
    scanf("%d",&primenumber);

    if ( primenumber >= 1 )
    {
       printf("First %d prime numbers are :\n",primenumber);
       printf("2\n");
    }

    for ( count = 2 ; count <= primenumber ;  )
    {
       for ( x = 2 ; x <= num - 1 ; x++ )
       {
          if ( num%x == 0 )
             break;
       }
       if ( x == num )
       {
          printf("%d\n",num);
          count++;
       }
       num++;
    }         

    return 0;
 }

If you can print the first 500 prime numbers, you should be able to tweak the program to print ONLY the 500th prime number. You are printing in line 30. Do an if-test on the count variable. Execute line 30 ONLY if count is the correct value. In other words, assuming your program indeed works as described, adding a single if statement to the code should make the program do what you want, not counting the obvious and trivial adjustments to lines 15 to 19.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.