You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
main()
{
int limit,i,j,flag=0,a=0,temp1,temp2,tempflag=1,count=0,t=0,newcount,arr[50];
printf("\nEnter limit:");
scanf("%d",&limit);
printf("\n TWIN PRIME:\n");
for(i=2;count<limit;i++)
{
for(j=2;j<=i/2;j++)
{
//if(i==j)
//j+=1;
if(i%j==0)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==0)
{
// printf("\n%d",i);
arr[t]=i;
t++;
newcount=t;
//a++;
if(tempflag==1)
{
temp1=i;
tempflag=0;
// printf(" temp1=%d",temp1);
}
else if(tempflag==0)
{
temp2=i;
tempflag=1;
//printf(" temp2=%d",temp2);
}
if((temp1-temp2==2)&&(temp1!=0)&&(temp2!=0))
{
printf("\n %d, %d",temp2,temp1);
count++;
}
if((temp2-temp1)==2&&(temp1!=0)&&(temp2!=0))
{
printf("\n %d, %d",temp1,temp2);
count++;
}
}
}
for(t=0;t<newcount;t++)
{

if(arr[t+1]-arr[t]==2)
printf("\nusing arrays %d, %d",arr[t],arr[t+1]);
}
getch();
}

You might also like