Prime Numbers

+2 Akhilesh Chobey · November 18, 2015
How do I print prime numbers between any two given numbers?
for e.g.
Between 2 and 10
2,3,5,7

Likewise between any two numbers.
Thanks :)

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
+2 Jon Z. · November 18, 2015
This should do.

void printPrimes(int start, int end){
    int i, j, k;
    for (i=start;i<=end;i++){
k = 0;
for(j=2;j<i;j++){
if(i%j == 0){
k++;
}
}
if (k == 0){
printf("%d\n", i);
}
}
}
  • 1
  • 2

C

124,555 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator