Created
January 14, 2018 02:39
-
-
Save pedro-m-g/7ada276cd9fda6eee3cb585b676d0ecd to your computer and use it in GitHub Desktop.
Print prime numbers
This file contains 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> | |
#include <stdbool.h> | |
void printAllPrimes(int, int); | |
int main() | |
{ | |
int lower, higher; | |
printf("Lower: "); | |
scanf("%d", &lower); | |
printf("Higher: "); | |
scanf("%d", &higher); | |
printAllPrimes(lower, higher); | |
return 0; | |
} | |
void printAllPrimes(int lower, int higher) | |
{ | |
int x, i; | |
bool isPrime; | |
for (x = lower; x <= higher; x++) | |
{ | |
isPrime = true; | |
for (i = 2; i < x; i++) | |
{ | |
if (x % i == 0) | |
{ | |
isPrime = false; | |
break; | |
} | |
} | |
if (isPrime) | |
{ | |
printf("%d ", x); | |
} | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment