New Android apps UniqueKey

Sunday, 22 February 2015

Prime numbers b/w given interval


/* A C program to display all prime numbers between given interval. */

#include <stdio.h>

main()
{
  int n1, n2, i, j, c;
  
  printf("Enter two numbers :   ");
  
  scanf("%d %d", &n1, &n2);
  printf("Prime numbers between %d and %d are: ", n1, n2);
  for(i=n1+1;i<n2;i++)
  {
      c=0;
      for(j=2;j<=i/2;j++)
      {
        if(i%j==0)
        {
          c=1;
          break;
        }
      }
      if(c==0)
        printf("%d ",i);
  }
}

No comments:

Post a Comment