Created
February 24, 2019 21:00
-
-
Save arraytools/818e533754130153e37b9c19bcd8c9c6 to your computer and use it in GitHub Desktop.
Source code is from https://www.programiz.com/c-programming/examples/prime-interval-function
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 checkPrimeNumber(int n); | |
| int main() | |
| { | |
| int n1, n2, i, flag; | |
| printf("Enter two positive integers: "); | |
| scanf("%d %d", &n1, &n2); | |
| printf("Prime numbers between %d and %d are: ", n1, n2); | |
| for(i=n1+1; i<n2; ++i) | |
| { | |
| // i is a prime number, flag will be equal to 1 | |
| flag = checkPrimeNumber(i); | |
| if(flag == 1) | |
| printf("%d ",i); | |
| } | |
| print("\n"); | |
| return 0; | |
| } | |
| // user-defined function to check prime number | |
| int checkPrimeNumber(int n) | |
| { | |
| int j, flag = 1; | |
| for(j=2; j <= n/2; ++j) | |
| { | |
| if (n%j == 0) | |
| { | |
| flag =0; | |
| break; | |
| } | |
| } | |
| return flag; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment