Posts Tagged ‘Prime Range’

/* Program to print the prime numbers within a range */

#include<stdio.h>

main()
{
int rangeStart,rangeEnd,i,j,flag;
printf(“\nStart of range: “);
scanf(“%d”,&rangeStart);
printf(“\nEnd of range: “);
scanf(“%d”,&rangeEnd);
for(i=rangeStart;i<=rangeEnd;i++)
{
flag=0;
for(j=2;j<=i/2;j++)
if(i%j==0)
flag=1;
if(flag==0)
printf(“%d\t”,i);
}
printf(“\n\n”);
}

Advertisements