Saturday 18 November 2017

C++ Program to Implement Sieve of eratosthenes to Generate Prime Numbers Between Given Range


Code:

#include   iostream
const int len = 100;

int main()
{
    int arr[100] = {0};

    for (int i = 2; i < 100; i++)
    {
        for (int j = i * i; j < 100; j+=i)
        {
            arr[j - 1] = 1;
        }
    }
    for (int i = 1; i < 100; i++)
    {
        if (arr[i - 1] == 0)
            std::cout << i << "\t";
    }
}


Output:

1       2       3       5       7       11      13      17      19      23
29      31      37      41      43      47      53      59      61      67
71      73      79      83      89      97


More C++ Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...