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 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

C Program to check whether the given number is prime or not. Print the suitable messages.

C Program to check whether the given number is prime or not and Print the suitable messages. 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 .

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!

(c) www.c-program-example.com