Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
March 21st, 2013, 01:00 AM
 SammA
Registered User

Join Date: Mar 2013
Posts: 1
Time spent in forums: 7 m 53 sec
Reputation Power: 0
Twin Prime Pairs

I already wrote some code to find prime numbers, now I have to write some code that prints out all the twin prime pairs under 1000... suggestions?

my code so far:

int x, m = 2;

printf("Enter a number to check if it is prime\n");
scanf("%d",&x);

for( m = 2 ; m*m <= x, ++m; ) {

if( n %m == 0 ){

printf("%d is not prime.\n", x);
break;
}
}
if( m == n ){
printf("%d is prime.\n", x);
}

thanks

P.S. I'm a super beginner, only been at this for a month or two. Be gentle if the above is wacky.

#2
March 21st, 2013, 08:46 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,170
Time spent in forums: 1 Month 3 Weeks 2 Days 10 h 27 m 9 sec
Reputation Power: 455
You don't have a program that prints prime numbers.
You don't have a program at all.

learn to use the compiler,
learn the essentials of a c program.
Turn on compiler warnings and address the issues that arise.

If you'd like accolades, your absolute beginner non-program is in some ways a good deal better than other absolute beginner nonsense that come through this forum.
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : March 21st, 2013 at 08:52 AM.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Twin Prime Pairs