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
Post a Comment