C program to generate and print prime numbers in a given range.

Write a C program to generate and print prime numbers in a given range. Also print the number of prime numbers.
Prime number is a whole number and greater than 1, which is divisible by one or itself.
Example: 2, 3, 5, 7, 11, 13………… Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/ #include <stdio.h>#include <conio.h>#include <stdlib.h>#include <math.h>void main(){ int M, N, i, j, flag, temp, count = 0; clrscr(); printf("Enter the value of M and Nn"); scanf("%d %d", &M,&N); if(N < 2) {  printf("There are no primes upto %dn", N);  exit(0); } printf("Prime numbers aren"); temp = M; if ( M % 2 == 0) {  M++; } for (i=M; i<=N; i=i+2) {  flag = 0;  for (j=2; j<=i/2; j++)  {   if( (i%j) == 0)   {    flag = 1;    break;   }  }  if(flag == 0)  {   printf("%dn",i);   count++;  } } printf("Number of primes between %d  and %d = %dn",temp,N,count);}`
`Read more Similar C ProgramsLearn C ProgrammingNumber System`

You can easily select the code by double clicking on the code area above.