right prime numbers
- From: johnmsimon@xxxxxxxxx
- Date: 7 Nov 2006 18:05:26 -0800
i need to develop a code that finds a prime right number between 2 and
100000. and print one line of text that indicates if the int. is right
prime. i am in beginning programing so complex is complicated. we are
on a functions chapter. i am usung the square root to find the prime.
so far i have accomplished this but i cant fgure how to divide this by
ten so i can find the right prime. i am using c.
#include <stdio.h>
#include <math.h>
int slowPrime(int); //function prototype
int main()
{
int x; // loop counter
int count = 0; // total numbers of prime found
long prime;
printf_s("The prime numbers from 1 to 10000 are:\n" );
for ( x = 2; x <= 2147483647 ; x++ )
{
if ( Prime( x ) )
{
++count; // count and print prime
//printf_s("%10d", x );
if ( count % 10 == 0 ) // new line after 10 values diplayed
printf_s( "\n" );
} // end for
} // end if
printf_s("%d prime numbers were found\n", count);
return 0; // indicate successful termination
} // end main
int isRightPrime( int n ) // slow prime returns 1 if n is prime
{
int i; // loop counter
for ( i = 2; i <= (int)sqrt (n); i++ )
{
if ( n % i == 0 )
return 0;
} // end for
return 1;
} // end function prime
i know this can not be as complicated as i have made it.
.
- Follow-Ups:
- Re: right prime numbers
- From: Don
- Re: right prime numbers
- From: Nick Keighley
- Re: right prime numbers
- From: Walter Roberson
- Re: right prime numbers
- From: Eric
- Re: right prime numbers
- From: Arthur J. O'Dwyer
- Re: right prime numbers
- Prev by Date: Re: OT: Q: C Unleashed - availability
- Next by Date: Re: Output to a control instead of the MS Dos box for C programs
- Previous by thread: " SNOWING over New York City Today November 7th 2006 "
- Next by thread: Re: right prime numbers
- Index(es):
Relevant Pages
|
|