Printing the Prime no (As per the user Input )


#include <iostream>
using namespace std;

void  primeno(int x)
{
int k ;

for (int i = 2; i < x; i++)
{
k = 0;

for (int j = 1; j <= i; j++)
{
if (i%j == 0)
{
k++;
}
}
if (k == 2)
{
cout << i << " " <<endl;
}

}


}

int main()
{
int primenosize;
        std::cout << "prime no \n" <<endl;

cout << "input range to print the prime no" <<endl;
cin >> primenosize;
primeno(primenosize);

return 0;
}

Comments

Popular posts from this blog

Dynamic Memory allocation in C++ for 1d, 2d and 3d array

Write Your Own String Class:

Printing the odd and even no using Pthread