Skip to content

Instantly share code, notes, and snippets.

@pedro-m-g
Created January 14, 2018 02:39
Show Gist options
  • Save pedro-m-g/7ada276cd9fda6eee3cb585b676d0ecd to your computer and use it in GitHub Desktop.
Save pedro-m-g/7ada276cd9fda6eee3cb585b676d0ecd to your computer and use it in GitHub Desktop.
Print prime numbers
#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