C Program to Display Prime Numbers Between Two Intervals

Here I shared C Program to Display Prime Numbers Between Two Intervals
and the problem takes a range and finds all the prime numbers between the range and print the numbers of prime numbers but the question is how to find prime numbers between two numbers.


#include<stdio.h>
int main()
{
 int init,end,i,j,flag,temp,count=0;
 printf("Enter the value of initial and end are \t");
 scanf("%d%d",&init,&end);
 if(end<2)
 {
  printf("\nThere are no prime numbers upto %d",end);
 }
 printf("\n Prime numbers are \n");
 temp=init;
 if(init%2==0)
 {
  init++;
 }
 for(i=init;i<=end;i=i+2)
 {
  flag=0;
  for(j=2;j<=i/2;j++)
  {
   if((i%j)==0)

   {
    flag=1;
    break;
   } 
  }
  if(flag==0)
  {
   printf("%d\n",i);
   count++;
  }
 }
 printf("\n Number of prime numbers between %d and %d is %d\n",temp,end,count);
 return 0;
}


OUTPUT:

Prime Numbers are
1
3
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

Number of Prime numbers between 0 to 99 is 25


NOTE: You have any problem in above C Program do not hesitate and write your problem in the comment box. I will support your problem.

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form