Hướng dẫn print first 10 prime numbers in c++ - in 10 số nguyên tố đầu tiên trong c ++

Số nguyên tố

Số nguyên tố là số tự nhiên có thể được chia cho bản thân hoặc 1 mà không có bất kỳ phần còn lại.

Ví dụ: 2, 3, 5, 7, 11, 13, 17, v.v. 2, 3, 5, 7, 11, 13, 17 etc.

Lưu ý: 2 là số thậm chí duy nhất.

Trong chương trình này, chúng ta cần in 10 số nguyên tố đầu tiên: 2,3,5,7,11,13,17,19,23,29.2,3,5,7,11,13,17,19,23,29.

Thuật toán

  • Bước 1: Bắt đầu START
  • Bước 2: Đặt ct = 0, n = 0, i = 1, j = 1 SET ct =0, n =0, i= 1, j=1
  • Bước 3: Lặp lại bước 4 đến 12 cho đến khi n REPEAT STEP 4 to 12 UNTIL n<10
  • Bước 4: J = 1 j =1
  • Bước 5: CT = 0 ct =0
  • Bước 6: Lặp lại bước 7 đến 9 cho đến khi j REPEAT STEP 7 to 9 UNTIL j<=i
  • Bước 7: Nếu i%j == 0 thì if i%j==0 then
  • Bước 8: CT = CT+1 ct = ct+1
  • Bước 9: J = J+1 j =j+1
  • Bước 10: Nếu CT == 2 thì in I if ct==2 then PRINT i
  • Bước 11: N = N+1 n =n+1
  • Bước 12: I = i+1 i = i+1
  • Bước 13: Kết thúc END

Chương trình Java

Output:

2,3,5,7,11,13,17,19,23,29

C chương trình

Output:

2,3,5,7,11,13,17,19,23,29

Chương trình Python

Output:

2,3,5,7,11,13,17,19,23,29

Chương trình C#

Output:

2,3,5,7,11,13,17,19,23,29

Chương trình PHP

Output:

2,3,5,7,11,13,17,19,23,29

Chủ đề tiếp theo##

Dưới đây là một chương trình để tìm các số nguyên tố

2,3,5,7,11,13,17,19,23,29
5 đầu tiên bằng cách sử dụng các vòng lặp
2,3,5,7,11,13,17,19,23,29
6 lồng nhau, trong đó giá trị của
2,3,5,7,11,13,17,19,23,29
5 được người dùng nhập vào.

Trước khi bạn tiếp tục với chương trình, hãy kiểm tra các chủ đề này để hiểu chương trình:

  • Vòng lặp trong c
  • Đối với các chương trình vòng lặp trong C
  • Lồng nhau cho các chương trình vòng lặp trong C
#include

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
    int n,i = 3, count, c;

    printf("\nEnter the number of prime numbers required :  ");
    scanf("%d", &n);

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

    // iteration for n prime numbers
    // i is the number to be checked in each iteration starting from 3
    for(count = 2; count <= n; i++)  
    {
        // iteration to check c is prime or not
        for(c = 2; c < i; c++)
        {
            if(i%c == 0)
                break;
        }

        if(c == i)  // c is prime
        {
            printf("%d ", i);
            count++;    // increment the count of prime numbers
        }

    }
    printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}
Đầu ra:

Output:

Hướng dẫn print first 10 prime numbers in c++ - in 10 số nguyên tố đầu tiên trong c ++



Đối với người mới bắt đầu, bạn cần khởi tạo cờ biến trong mỗi lần lặp của vòng ngoài cho vòng lặp trước vòng bên trong cho vòng lặp như ví dụ

for(k = 0,num = 3; k<10; k++,num++) {
    flag = 1;
    for (int i = 2; i <= sqrt(num); i++) {
    //...

Tuy nhiên, tốt hơn là đặt cờ trong trường hợp khi số là số nguyên tố. Ví dụ

for(k = 0,num = 3; k<10; k++,num++) {
    flag = 1;
    for (int i = 2; flag && i <= sqrt(num); i++) {
        if((num % i) == 0) flag = 0;
    }
    if(flag == 1)
        arr[j++] = num;

}

Vòng lặp bên ngoài được thực hiện chính xác 10 lần độc lập về số lượng số nguyên tố được tìm thấy.

Vì vậy, viết lại các vòng ít nhất thích

for ( num = 3; j < 10; num += 2 ) {
    flag = 1;
    for (int i = 3; flag && i <= sqrt(num); i += 2) {
        if((num % i) == 0) flag = 0;
    }
    if(flag == 1)
        arr[j++] = num;

}

Đây là một chương trình trình diễn. Tôi đổi tên

2,3,5,7,11,13,17,19,23,29
8 thành
2,3,5,7,11,13,17,19,23,29
9.

#include 

int main( void )
{
    enum { N = 10 };
    int arr[N];
    size_t j = 0;
    arr[j++] = 2;

    for ( int num = 3; j < N; num += 2 ) 
    {
        int prime = 1;
        for ( int i = 3; prime && i <= num / i; i += 2 ) 
        {
            if (( num % i ) == 0) prime = 0;
        }

        if ( prime ) arr[j++] = num;
    }

    printf( "First %d Prime Numbers: ", N );
    for (j = 0; j < N; j++) printf( "%d ", arr[j] );
    putchar( '\n' );
}

Đầu ra chương trình là

2,3,5,7,11,13,17,19,23,29
0

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    Đọc
    Examples: 

    2,3,5,7,11,13,17,19,23,29
    
    1

    Bàn luận  

    • Đưa ra một số n, nhiệm vụ là in các số nguyên tố từ 1 đến n.examples: & nbsp;
    • Thuật toán: & nbsp;
    • Đầu tiên, lấy số N làm đầu vào.

    Sau đó sử dụng một vòng lặp để lặp lại các số từ 1 đến n  Now, according to formal definition, a number ‘n’ is prime if it is not divisible by any number other than 1 and n. In other words a number is prime if it is not divisible by any number from 2 to n-1.

    Sau đó kiểm tra xem mỗi số là một số nguyên tố. Nếu nó là một số nguyên tố, in nó.

    C++

    2,3,5,7,11,13,17,19,23,29
    
    0

    Cách tiếp cận 1: & nbsp; Bây giờ, theo định nghĩa chính thức, một số ’n, là nguyên tố nếu nó không chia hết cho bất kỳ số nào khác ngoài 1 và n. Nói cách khác, một số là số nguyên tố nếu nó không chia hết cho bất kỳ số nào từ 2 đến N-1.

    Dưới đây là việc thực hiện phương pháp trên: & nbsp; & nbsp;

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    3

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    7

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    1

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    0

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    22____35

    2,3,5,7,11,13,17,19,23,29
    
    9

    Đầu ra

    2,3,5,7,11,13,17,19,23,29
    
    8

    Độ phức tạp về thời gian: O (n^(3/2)),

    Không gian phụ trợ: O (1)

    Bạn có thể tối ưu hóa thêm độ phức tạp thời gian thành O (N*log (log (n))). Kiểm tra eratosthenes.

    2,3,5,7,11,13,17,19,23,29
    
    4
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    Làm thế nào để bạn tìm thấy 10 số nguyên tố đầu tiên trong C?

    2,3,5,7,11,13,17,19,23,29
    
    9

    C chương trình.

    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    9

    for ( num = 3; j < 10; num += 2 ) {
        flag = 1;
        for (int i = 3; flag && i <= sqrt(num); i += 2) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    0

    Dưới đây là việc thực hiện phương pháp trên: & nbsp; & nbsp;

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    3

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    7

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    1

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    22____35

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    6
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    6

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    0

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    27
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    29
    2,3,5,7,11,13,17,19,23,29
    
    30

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    7

    2,3,5,7,11,13,17,19,23,29
    
    9

    Java

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    42
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    Các

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    62

    2,3,5,7,11,13,17,19,23,29
    
    63
    2,3,5,7,11,13,17,19,23,29
    
    0 ____165__151515222

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    83

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    88
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    90

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    49
    2,3,5,7,11,13,17,19,23,29
    
    97

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    63
    2,3,5,7,11,13,17,19,23,29
    
    02
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    04

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    Python3

    2,3,5,7,11,13,17,19,23,29
    
    12
    2,3,5,7,11,13,17,19,23,29
    
    13

    Các

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    36

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    16
    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    51
    2,3,5,7,11,13,17,19,23,29
    
    25

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    51

    2,3,5,7,11,13,17,19,23,29
    
    522____217
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8__

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    68

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    70
    2,3,5,7,11,13,17,19,23,29
    
    71
    2,3,5,7,11,13,17,19,23,29
    
    17
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    52

    C#

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    76

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    42
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    Các

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    62

    2,3,5,7,11,13,17,19,23,29
    
    63
    2,3,5,7,11,13,17,19,23,29
    
    0 ____165__151515222

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    83

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    88
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    90

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    49
    2,3,5,7,11,13,17,19,23,29
    
    97

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    29
    2,3,5,7,11,13,17,19,23,29
    
    30
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    32

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29 42,3,5,7,11,13,17,19,23,29 9

    2,3,5,7,11,13,17,19,23,29
    
    40

    2,3,5,7,11,13,17,19,23,29
    
    12
    2,3,5,7,11,13,17,19,23,29
    
    13

    2,3,5,7,11,13,17,19,23,29
    
    8

    Các

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    36

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    83

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    88
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    90

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    83

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    49
    2,3,5,7,11,13,17,19,23,29
    
    97

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    2

    2,3,5,7,11,13,17,19,23,29
    
    12
    2,3,5,7,11,13,17,19,23,29
    
    13
    O(N^2), 

    CácO(1)

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28
    :  For checking if a number is prime or not do we really need to iterate through all the number from 2 to n-1? We already know that a number ‘n’ cannot be divided by any number greater than ‘n/2’. So, according to this logic we only need to iterate through 2 to n/2 since number greater than n/2 cannot divide n.

    C++

    2,3,5,7,11,13,17,19,23,29
    
    0

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    36

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    51

    2,3,5,7,11,13,17,19,23,29
    
    522____217
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8__

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    22____35

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    6
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    6

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    0

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    76

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    46
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    7

    2,3,5,7,11,13,17,19,23,29
    
    9

    Java

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    42
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    Các

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    61
    2,3,5,7,11,13,17,19,23,29
    
    62

    2,3,5,7,11,13,17,19,23,29
    
    63
    2,3,5,7,11,13,17,19,23,29
    
    0 ____165__151515222

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    83

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    88
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    90

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    60
    2,3,5,7,11,13,17,19,23,29
    
    49
    2,3,5,7,11,13,17,19,23,29
    
    97

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    29
    2,3,5,7,11,13,17,19,23,29
    
    02
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    04

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    Python3

    2,3,5,7,11,13,17,19,23,29
    
    12
    2,3,5,7,11,13,17,19,23,29
    
    13

    Các

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    Is

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    16
    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    51
    2,3,5,7,11,13,17,19,23,29
    
    25

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    51

    2,3,5,7,11,13,17,19,23,29
    
    522____217
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8__

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    68

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    70
    2,3,5,7,11,13,17,19,23,29
    
    71
    2,3,5,7,11,13,17,19,23,29
    
    17
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    52

    C#

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    76

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    98
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    0 ____606
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    14

    2,3,5,7,11,13,17,19,23,29
    
    2____
    2,3,5,7,11,13,17,19,23,29
    
    0____617
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    15

    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    20

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    30

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    30
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    32

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    JavaScript

    2,3,5,7,11,13,17,19,23,29
    
    40

    2,3,5,7,11,13,17,19,23,29
    
    41
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    56

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    66

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0 ____359____33
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    22____35

    2,3,5,7,11,13,17,19,23,29
    
    9

    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    82

    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    84

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    88

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    2
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    92
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    04

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    87

    Đầu ra

    2,3,5,7,11,13,17,19,23,29
    
    2

    Độ phức tạp về thời gian: O (N2), & NBSP;O(N2), 

    Không gian phụ trợ: O (1), vì không có thêm không gian.O(1),since no extra space has been taken.

    Cách tiếp cận 3: Nếu một số ’n, không được chia cho bất kỳ số nào nhỏ hơn hoặc bằng với căn bậc hai của n thì, nó sẽ không được chia cho bất kỳ số nào khác lớn hơn căn bậc hai của n. Vì vậy, chúng ta chỉ cần kiểm tra đến căn bậc hai của n.If a number ‘n’ is not divided by any number less than or equals to the square root of n then, it will not be divided by any other number greater than the square root of n. So, we only need to check up to the square root of n.

    C++

    2,3,5,7,11,13,17,19,23,29
    
    0

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    3

    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    0 ____606
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    17

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    15

    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    20

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    30

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    2
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    0
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29 80 2,3,5,7,11,13,17,19,23,29 41 2,3,5,7,11,13,17,19,23,29 82 2,3,5,7,11,13,17,19,23,29 15

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    98
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    0 ____606
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    14

    2,3,5,7,11,13,17,19,23,29
    
    2____
    2,3,5,7,11,13,17,19,23,29
    
    0____617
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    15

    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    20

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    30

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    02
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    04

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    Python3

    2,3,5,7,11,13,17,19,23,29
    
    12
    2,3,5,7,11,13,17,19,23,29
    
    13

    Các

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    JavaScript

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    16
    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    17
    2,3,5,7,11,13,17,19,23,29
    
    51
    2,3,5,7,11,13,17,19,23,29
    
    25

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    28

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    51

    2,3,5,7,11,13,17,19,23,29
    
    522____217
    2,3,5,7,11,13,17,19,23,29
    
    89
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    31
    2,3,5,7,11,13,17,19,23,29
    
    32
    2,3,5,7,11,13,17,19,23,29
    
    33
    2,3,5,7,11,13,17,19,23,29
    
    8__

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    68

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    70
    2,3,5,7,11,13,17,19,23,29
    
    71
    2,3,5,7,11,13,17,19,23,29
    
    17
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    52

    C#

    2,3,5,7,11,13,17,19,23,29
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    76

    2,3,5,7,11,13,17,19,23,29
    
    37
    2,3,5,7,11,13,17,19,23,29
    
    38

    2,3,5,7,11,13,17,19,23,29
    
    8

    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    98
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    45

    2,3,5,7,11,13,17,19,23,29
    
    40
    2,3,5,7,11,13,17,19,23,29
    
    0 ____606
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    17

    2,3,5,7,11,13,17,19,23,29
    
    2____
    2,3,5,7,11,13,17,19,23,29
    
    0____617
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    2
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    80
    2,3,5,7,11,13,17,19,23,29
    
    41
    2,3,5,7,11,13,17,19,23,29
    
    82
    2,3,5,7,11,13,17,19,23,29
    
    15

    2,3,5,7,11,13,17,19,23,29
    
    85

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    20

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    8
    2,3,5,7,11,13,17,19,23,29
    
    6
    2,3,5,7,11,13,17,19,23,29
    
    30

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    2
    2,3,5,7,11,13,17,19,23,29
    
    30
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; flag && i <= sqrt(num); i++) {
            if((num % i) == 0) flag = 0;
        }
        if(flag == 1)
            arr[j++] = num;
    
    }
    
    1
    2,3,5,7,11,13,17,19,23,29
    
    32

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9

    JavaScript

    2,3,5,7,11,13,17,19,23,29
    
    40

    #include 
    
    int main( void )
    {
        enum { N = 10 };
        int arr[N];
        size_t j = 0;
        arr[j++] = 2;
    
        for ( int num = 3; j < N; num += 2 ) 
        {
            int prime = 1;
            for ( int i = 3; prime && i <= num / i; i += 2 ) 
            {
                if (( num % i ) == 0) prime = 0;
            }
    
            if ( prime ) arr[j++] = num;
        }
    
        printf( "First %d Prime Numbers: ", N );
        for (j = 0; j < N; j++) printf( "%d ", arr[j] );
        putchar( '\n' );
    }
    
    65

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    0 ____968
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    6
    #include 
    
    int main( void )
    {
        enum { N = 10 };
        int arr[N];
        size_t j = 0;
        arr[j++] = 2;
    
        for ( int num = 3; j < N; num += 2 ) 
        {
            int prime = 1;
            for ( int i = 3; prime && i <= num / i; i += 2 ) 
            {
                if (( num % i ) == 0) prime = 0;
            }
    
            if ( prime ) arr[j++] = num;
        }
    
        printf( "First %d Prime Numbers: ", N );
        for (j = 0; j < N; j++) printf( "%d ", arr[j] );
        putchar( '\n' );
    }
    
    74

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    3
    2,3,5,7,11,13,17,19,23,29
    
    4
    2,3,5,7,11,13,17,19,23,29
    
    5

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    9
    2,3,5,7,11,13,17,19,23,29
    
    3
    #include
    
    int main()
    {
        printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
        int n,i = 3, count, c;
    
        printf("\nEnter the number of prime numbers required :  ");
        scanf("%d", &n);
    
        if(n >= 1)
        {
            printf("\n\nFirst %d prime numbers are :  ", n);
            printf("2 ");
        }
    
        // iteration for n prime numbers
        // i is the number to be checked in each iteration starting from 3
        for(count = 2; count <= n; i++)  
        {
            // iteration to check c is prime or not
            for(c = 2; c < i; c++)
            {
                if(i%c == 0)
                    break;
            }
    
            if(c == i)  // c is prime
            {
                printf("%d ", i);
                count++;    // increment the count of prime numbers
            }
    
        }
        printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
        return 0;
    }
    22____35

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    for(k = 0,num = 3; k<10; k++,num++) {
        flag = 1;
        for (int i = 2; i <= sqrt(num); i++) {
        //...
    
    82

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    6
    #include 
    
    int main( void )
    {
        enum { N = 10 };
        int arr[N];
        size_t j = 0;
        arr[j++] = 2;
    
        for ( int num = 3; j < N; num += 2 ) 
        {
            int prime = 1;
            for ( int i = 3; prime && i <= num / i; i += 2 ) 
            {
                if (( num % i ) == 0) prime = 0;
            }
    
            if ( prime ) arr[j++] = num;
        }
    
        printf( "First %d Prime Numbers: ", N );
        for (j = 0; j < N; j++) printf( "%d ", arr[j] );
        putchar( '\n' );
    }
    
    95

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    8

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    0
    2,3,5,7,11,13,17,19,23,29
    
    00

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    002

    2,3,5,7,11,13,17,19,23,29
    
    46
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    9

    2,3,5,7,11,13,17,19,23,29
    
    14
    2,3,5,7,11,13,17,19,23,29
    
    87

    Đầu ra

    2,3,5,7,11,13,17,19,23,29
    
    2

    Độ phức tạp về thời gian: O (n^(3/2)), O(N^(3/2)),

    Không gian phụ trợ: O (1)O(1)

    Bạn có thể tối ưu hóa thêm độ phức tạp thời gian thành O (N*log (log (n))). Kiểm tra eratosthenes.O(n*log(log(n))). CheckSieve of Eratosthenes.


    Làm thế nào để bạn tìm thấy 10 số nguyên tố đầu tiên trong C?

    C chương trình..
    #bao gồm .
    int main ().
    int ct = 0, n = 0, i = 1, j = 1 ;.
    while(n

    Làm cách nào để in số N Prime đầu tiên?

    Cách tiếp cận 1: Bây giờ, theo định nghĩa chính thức, một số 'n' là số nguyên tố nếu nó không chia hết cho bất kỳ số nào khác ngoài 1 và n ...
    Đầu tiên, lấy số N làm đầu vào ..
    Sau đó sử dụng một vòng lặp để lặp lại các số từ 1 đến n ..
    Sau đó kiểm tra xem mỗi số là một số nguyên tố.Nếu đó là số nguyên tố, hãy in nó ..

    Làm thế nào để bạn in số nguyên tố từ 1 đến 100 C cho vòng lặp?

    Phương pháp 1..
    Đặt giới hạn dưới = 1, giới hạn trên = 100 ..
    Chạy một vòng lặp trong lần lặp của (i) b/w các giới hạn này ..
    Đối với mỗi, tôi kiểm tra xem số nguyên tố của nó hoặc không sử dụng Chức năng kiểm tra (I).
    Nếu tôi in Prime, nó sẽ chuyển sang lặp tiếp theo ..