Jan 25, 2022

Finding Nth Prime Number (C Language)

Use of Nested For loop and if statements.

 #include <stdio.h>
int main()
{
    int prime, rankOfPrime;
    rankOfPrime = 0;
    for (int prime = 2; rankOfPrime <= 10001; prime++)
    {
        int count = 0;
        for (int i = 2; i <= prime / 2; i++)
        {
            if (prime % i == 0)
            {
                count++;
            }
        }
        if (count == 0)
        {
            rankOfPrime++;
            printf("%d :", prime);
            printf("%d\n", rankOfPrime);
        }
    }

    return 0;
}

No comments:

Post a Comment

Comparing two files in C language.

Operations on More than one File.    # include < stdio.h > # include < stdlib.h > # include < string.h > int main ( int ...