New Android apps UniqueKey

Friday, 15 May 2015

Prime numbers between 2 numbers


#include<stdio.h>
#include<math.h>

main()
{
 int n1,n2,i,j,flag;
 
 printf("Enter 2 numbers\n");
 scanf("%d %d",&n1,&n2);
 
 for(i=n1+1 ; i<n2 ; i++)
 {
  flag = 0;
  
  for(j=2 ; j<=sqrt(i) ; j++)
  {
   if(i%j==0){
    flag=1;
    break;
   }
  }
  if(flag==0)
  printf("%d\t",i);
 }
}

No comments:

Post a Comment