Finding the prime numbers between two given integers in the minimum number of comparisons:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
clrscr();
int i,n,count,n1,n2;
printf("Enter n1 and n2:");
scanf("%d",&n1);
scanf("%d",&n2);
n=n1;
int c=0; //variable to store number of comparisions (number of times while() runs)
for(n=n1;n<=n2;n1++,n=n1)
{
count=0; //number of factors found
i=2;
while((n>0)&&(i<=sqrt(n))) //condition for minimum comparisions
{
printf("\n\t%d",c++);//printing the comparision number
if(n%i==0)
{
count++;
n/=i;
}
else i++;
}
if(count==0)
printf("\n%d",n1);
}
getch();
}