[Solved] Why it doesn’t generate me first n prime numbers?


Instead of (prim); use if(prim). The rest of your code is correct.

#include <iostream>

using namespace std;

int main()
{
 unsigned int i,n,d;
 bool prim;
 cout<<"n=";
 cin>>n;
 for(i=2;i<=n;i=i+1)
    {
     prim=true;
     for(d=2;d<=i/2;d=d+1)
     if(i%d==0)
     {
         prim=false;
         break;
     }
     if(prim)
         cout<<i<<", ";
    }
  return 0;
}

0

solved Why it doesn’t generate me first n prime numbers?