A pair of (positive) integer numbers are called twin primes if they are both prime numbers and the difference between them is 2, i.e. they are consecutive odd numbers and they are prime numbers. (3, 5), (5, 7) and (11, 13) are three examples of such pair of twin prime numbers.

Write a program to display all the pairs of twin prime numbers which are less than 100.
Caution: You need to write a program to find and list all the twin primes. If you just list all of the twin prime numbers, you will get 0 credit.

thank you.

Recommended Answers

All 4 Replies

You should also get 0 credit if someone else writes the program for you.

I can do this in a couple of minutes for a low rate of $20.00 US dollars.

I did my best,but the result is far from what should appear. I'd appreciate it if any body can correct my mistake.

#include "stdafx.h"
#include "simpio.h"
#include "genlib.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
	int i,j,n;
	for (i=2;i<=100;i++)
	{
	     for (j=2;j<=sqrt((double)i)+1;j++);
		 {
			 n=j%i;
			 if (n!=0)
			 {
				 printf("%d,%d",i,i);
			 }
		 }
	}
}

---------------------------------------------------------------------------------
I did my best,but the result is far from what should appear. I'd appreciate it if any body can correct my mistake.

#include<stdio.h>
void main()
{
int n,i,j;
cout<<"up to where u want twins";
cin>>n;
for(i=2;i<n;i++)
{
flag=0;
for(j=2;j<=sqrt((double)i);j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==1)
{

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.