C program to print the Prime Numbers Between The two Numbers / Given range
/* c program to print prime numbers between given range */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include<stdio.h> //#include<conio.h> int main() { int i,j,count,min,max; //clrscr(); printf(" Enter min range: "); scanf("%d",&min); printf(" Enter max range: "); scanf("%d",&max); //since zero is not a prime number if(min==0) { min=min+1; } printf("\n The Prime Numbers Between %d And %d are: \n",min,max); for(i = min;i<=max;i++) { count = 0; for(j=2;j<=i/2;j++) { if(i%j==0) { count++; break; //to come out of if loop.. } } //since 1 is not a prime number if(count==0 && i!= 1 ) printf(" %d",i); } printf("\n\n"); //getch(); return (0); } |
Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )
Best way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |