Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Example Program For Find Prime Number Using For Loop In C++
SUBMITTED BY:
Nrupeshsinh
DATE:
June 24, 2016, 8:27 a.m.
FORMAT:
Text only
SIZE:
652 Bytes
Raw
Download
Tweet
HITS:
845
Go to comments
Report
#include<iostream>
#include<conio.h>
#include<math.h> // Math.h For sqrt function
using namespace std;
int main()
{
// Variable Declaration
int n;
// Get Input Value
cout<<"Enter the Number :";
cin>>n;
cout<<"List Of Prime Numbers Below "<<n<<endl;
//for Loop Block For Find Prime Number
for (int i=2; i<n; i++)
for (int j=2; j*j<=i; j++)
{
if (i % j == 0)
break;
else if (j+1 > sqrt(i)) {
cout << i << endl;
}
}
// Wait For Output Screen
getch();
return 0;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus