Created
December 24, 2014 06:11
-
-
Save scratchyourbrain/1d9f72b09d97a7c64449 to your computer and use it in GitHub Desktop.
C Program to Display Prime Numbers Between Two Intervals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
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
is there any other logic to solve this problem,in a much efficient way??