Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create PRIME NUMBERS BETWEEN TWO INTERVALS #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions PRIME NUMBERS BETWEEN TWO INTERVALS
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <iostream>

#include<conio.h>

using namespace std;

int main()

{

int n1,n2,p;

cout<<"Enter the range to print the prime numbers:\n";

cin>>n1>>n2;



for(int i=n1;i<=n2;i++) //loop will run from first number till last number

{

p=1; /*by default we'll take value as 1 and when the next loop will start then it'll turn this value as 0 while violating the condition of being a prime number*/

for(int j=2;j<=i/2;j++) /*this loop will run from 2 as to check that the number is not getting divided by any natural number(condition of prime number)*/

{

if(i%j==0) /*this is checking that the number is not getting divided by any natural number*/

{

p=0; /*p=0 when the number is divided by other natural numbers(violation of condition of prime number)*/

break;

}

}

if(p==1)

cout<<i<<", ";

}

return 0;


}