prime right numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ETM11871
    New Member
    • Nov 2006
    • 1

    prime right numbers

    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.
Working...