0
#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int num)
{
    bool pno[num + 1];
    memset(pno, true, sizeof(pno));
    for (int i = 2; i* i < = num; i++)
    {
        if (pno[i] == true)
        {
            for (int j = i * 2; j < = num; j + = i)
                pno[j] = false;
        }
    }
    for (int i = 2; i < = num; i++)
        if (pno[i])
            cout << i << " ";
}
int main()
{
    int num = 15;
    cout << "The prime numbers smaller or equal to " << num << " are: ";
    SieveOfEratosthenes(num);
    return 0;
}

the error is in the for loop. According to me the code is correct.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
phatballz
  • 3
  • 2

1 Answers1

0

Try removing space before =.

for(int i=2; i*i<= num; i++) { ..
mch
  • 9,424
  • 2
  • 28
  • 42