Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scratchyourbrain/1d9f72b09d97a7c64449 to your computer and use it in GitHub Desktop.
Save scratchyourbrain/1d9f72b09d97a7c64449 to your computer and use it in GitHub Desktop.
C Program to Display Prime Numbers Between Two Intervals
#include <stdio.h>
int main()
{
int n1, n2, i, j, flag;
printf("Enter two numbers(intevals): ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
flag=0;
for(j=2; j<=i/2; ++j)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d ",i);
}
return 0;
}
@nishant1ranjan
Copy link

is there any other logic to solve this problem,in a much efficient way??

@trmesusaw
Copy link

printf("Prime numbers between %d and %d are: ", n1, n2);
WHAT ACTUALLY THIS LINE MEAN??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment