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;


printf("Enter the value of M and Nn");
scanf("%d %d", &M,&N);

if(N < 2)
printf("There are no primes upto %dn", N);
printf("Prime numbers aren");
temp = M;

if ( M % 2 == 0)
for (i=M; i<=N; i=i+2)
flag = 0;

for (j=2; j<=i/2; j++)
if( (i%j) == 0)
flag = 1;
if(flag == 0)
printf("Number of primes between %d and %d = %dn",temp,N,count);

Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

Leave a Reply