C++ Program To Print All Prime Number Between 1 And N
//C++ Program To Print All Prime Number Between 1 And N
#include<iostream>
using namespace std;
int main()
{
int num,prime;
cout<<"Enter The Nth Number:--";
cin>>num;
for(int i=1;i<=num;i++)
{prime=0;
for(int j=2;j<i;j++)
{if(i%j==0)
prime=1;
}
if(prime==0)
cout<<i<<",";
}
return 0;
}
//C++ Program To Print All Prime Number Between 1 And N
using namespace std;
int main()
{
int num,prime;
cout<<"Enter The Nth Number:--";
cin>>num;
for(int i=1;i<=num;i++)
{prime=0;
for(int j=2;j<i;j++)
{if(i%j==0)
prime=1;
}
if(prime==0)
cout<<i<<",";
}
return 0;
}
0 Comments