/* c program to print prime numbers between given range */

#include<stdio.h>

//#include<conio.h>

int main()

{

int i,j,count,min,max;

//clrscr();

printf(" Enter min range: ");

scanf("%d",&min);

printf(" Enter max range: ");

scanf("%d",&max);

if(min==0) //since zero is not a prime number

min=min+1;

printf("\n The Prime Numbers Between %d And %d

are: \n",min,max);

for(i = min;i<=max;i++)

{

count = 0;

for(j=2;j<=i/2;j++)

{

if(i%j==0)

{

count++;

break; //to come out of if loop..

}

}

if(count==0 && i!= 1 ) //since 1 is not a prime number

printf(" %d",i);

}

printf("\n\n");

//getch();

return (0);

}

Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

#include<stdio.h>

//#include<conio.h>

int main()

{

int i,j,count,min,max;

//clrscr();

printf(" Enter min range: ");

scanf("%d",&min);

printf(" Enter max range: ");

scanf("%d",&max);

if(min==0) //since zero is not a prime number

min=min+1;

printf("\n The Prime Numbers Between %d And %d

are: \n",min,max);

for(i = min;i<=max;i++)

{

count = 0;

for(j=2;j<=i/2;j++)

{

if(i%j==0)

{

count++;

break; //to come out of if loop..

}

}

if(count==0 && i!= 1 ) //since 1 is not a prime number

printf(" %d",i);

}

printf("\n\n");

//getch();

return (0);

}

Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

ReplyDeleteBest way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.

ReplyDelete