7 - 10001st_prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

link

cevap : 104743

#include <stdio.h>
#pragma hdrstop
#include <tchar.h>

// fonksiyon prototipleri
unsigned char sayi_asal_mi(unsigned int, unsigned int *);

#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
    unsigned int analiz_sayisi = 110000;
    unsigned int i,j;
    unsigned int counter=0;
    unsigned char sayi_asal_flag=0;
    unsigned int sayi_asal_counter = 0;

    for (i=2; i<analiz_sayisi+1; i++) {
        sayi_asal_flag = sayi_asal_mi(i, &counter);
        counter = 0;
        sayi_asal_counter = sayi_asal_flag + sayi_asal_counter;

        if (sayi_asal_counter == 10001) {
            break;
        }
    }

    printf("10001. sayi = %d\n", i);

    system("pause");
}

unsigned char sayi_asal_mi(unsigned int sayi, unsigned int *counter) {

    unsigned int i;

    for (i = 2; i < sayi; i ++) {
        if (sayi % i == 0)
            *counter = *counter+1;
    }

    if (*counter==0) {
        return 1;
    }else{
        return 0;
    }
}