# Thread: twin prime numbers problem

1. ## twin prime numbers problem

hi all well this my first ever post here and i wanna learn from here as much i can.. i had many chances to learn c but took it for granted this time i really wanna do it.
still i am a begginer i am not able to develop logics i.e i know things how to do them but i can implement them in C language plz help me....

from last two days i struggling through a program i dont know how should i solve it

program is:- two prime no.s are said to be twin if they differ by 2 such as 11 and 13,17-19,etc
WAP to print all TWO digit twin prime numbers

I cud just try how to check whether a number is prime or not plz check my code
Code:
```#include<stdio.h>
main()
{
int n,i;
printf("\n please enter the number to check whether a  prime or not);
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("\n no. is not prime");
return;
}
else
{
if(n==i)
printf(" no is prime);
}}}```

please do tell me how can i make problems solving simpler. do guide me please i am dying to learn c

2. Code:
```          for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("\n no. is not prime");
return;
}
else
{
if(n==i)   ///////////// Will this ever be true??
printf(" no is prime);```
Jim

3. ## rechecking

Code:
```#include<stdio.h>
main()
{
int n,i;
printf("\n please enter to check whether a  prime or not);
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("\n no. is not prime");
break;
}
else
{
if(n=i)
printf(" no is prime);
}}}```

4. singh751, it is good that you posted in code bbcode tags, but you really need to format your code properly, e.g.,
Code:
```#include<stdio.h>

int main(void)
{
int n, i;
printf("\n please enter to check whether a  prime or not);
scanf("%d", &n);
for (i = 2; i < n; i++)
{
if (n % i == 0)
{
printf("\n no. is not prime");
break;
}
else
{
if (n == i)
printf(" no is prime);
}
}
return 0;
}```
I added the return type of the main function.

5. My point in my fist post is:
Code:
```#include <stdio.h>

int main()
{
int a, n;
for(a= 0; a < n;n++)
{
if(a == n)
{
printf("Hi.");
}
}
return(0);
}```
Does this print "Hi"?

6. First, read this Sieve of Eratosthenes - Wikipedia, the free encyclopedia

Second write a function with this prototype
int isPrime ( int n );
It returns 1 if the number is prime, and 0 if it is not prime.

Before doing the second part of your assignment, make sure this function works by just printing each 2...n as being prime or non-prime

7. Originally Posted by Salem
First, read this Sieve of Eratosthenes - Wikipedia, the free encyclopedia

Second write a function with this prototype
int isPrime ( int n );
It returns 1 if the number is prime, and 0 if it is not prime.

Before doing the second part of your assignment, make sure this function works by just printing each 2...n as being prime or non-prime
dear i am just a beginner i have not yet started functions
but i will try to do this with functions when i am done with basic concepts so please help me

8. Or just try to do the same thing in main() - print each number and whether it is prime or not.

Divide the problem into steps, and tackle each one in turn.