Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

7 Aug 2012

C program to print the Prime Numbers Between The two Numbers / Given range

/* 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(); ) 


2 comments:

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