#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int number,num1=1,count=0,num3=2,previous=2;
cout<<"Enter the upper limit= ";
cin>>number;
cout<<"\nThe twin primes from 1 till " <<number<< " are\n";
while(num1<=number)
{
num3=2;
count=0;
while(num3<num1)
{
if(num1%num3==0)
{
count++;
}
num3++;
}
if(count==0)
{
if(num1-previous==2)
{
cout<<"["<<previous<<","<<num1<<"]"<<endl;
}
previous=num1;
}
num1++;
}
getch();
}
#include<conio.h>
void main()
{
clrscr();
int number,num1=1,count=0,num3=2,previous=2;
cout<<"Enter the upper limit= ";
cin>>number;
cout<<"\nThe twin primes from 1 till " <<number<< " are\n";
while(num1<=number)
{
num3=2;
count=0;
while(num3<num1)
{
if(num1%num3==0)
{
count++;
}
num3++;
}
if(count==0)
{
if(num1-previous==2)
{
cout<<"["<<previous<<","<<num1<<"]"<<endl;
}
previous=num1;
}
num1++;
}
getch();
}
No comments:
Post a Comment