-1

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.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by BhaskaR RaO
Featured Replies
0

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.

0

#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)
{

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.