Wednesday, July 29, 2020

Write a Program find Next Prime number in C++.

Next Prime number in C++.


#include<iostream>
using namespace std;
int main()
{
int p,q=2,number;
cout<<"Enter any num: ";
cin>>number;
cout<<"Next prime num: ";
for(p=number+1;p<3000;p++)
{
for(q=2;q<p;q++)
{
if(p %q==0)
{
break;
}
}
if(p==q || p==1)
{
cout<<"\t"<<p;
break;
}
}
return 0;
}


OUTPUT

Enter any num: 21
Next prime num: 23

No comments:

Post a Comment

Please do not any spam link in Comment Box