C Programming Code Examples C > Mathematics Code Examples C Program to find prime numbers in a given range C Program to find prime numbers in a given range Upon execution of below program, the user would be asked to provide the from & to range and then the program would display all the prime numbers in sequential manner for the provided range. Using this program you can find out the prime numbers between 1 to 100, 100 to 999 etc. You just need to input the range, for e.g. if you want the prime numbers from 100 to 999 then enter numbers 100 and 999 when program prompts for input. Program to find prime numbers #include <stdio.h> int main() { int number1, number2, flag_var, i, x; /* Ask user to input the from/to range * like 1 to 100, 10 to 1000 etc. */ printf("Enter two range(input integer numbers only):"); //Store the range in variables using scanf scanf("%d %d", &number1, &number2); //Display prime numbers for input range printf("Prime numbers from %d and %d are:\n", number1, number2); for(i=number1+1; i<number2; ++i) { flag_var=0; for(x=2; x<=i/2; ++x) { if(i%x==0) { flag_var=1; break; } } if(flag_var==0) printf("%d\n",i); } return 0; }