C program to find prime numbers between given range


#include<stdio.h>
void main()
{
int i, prime, upper, lower, n;

printf("\n\n\t ENTER THE LOWER LIMIT => ");
scanf("%d", &lower);
printf("\n\n\t ENTER THE UPPER LIMIT => ");
scanf("%d", &upper);
printf("\n\n\t PRIME NUMBERS ARE");
for(n=lower+1; n<upper; n++)
{
prime = 1;
for(i=2; i<n; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
printf("\n\n\t\t\t%d", n);
}
}

Output :-

ENTER THE LOWER LIMIT => 0
ENTER THE UPPER LIMIT =>  10

PRIME NUMBERS ARE

1

2

3

5

7

2 comments :

  1. its excillent which help me in project

    ReplyDelete
  2. If i want prime numbers between 1 to 100! This program will work ot not??

    ReplyDelete