1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

find the prime no. less than 10 digits

Discussion in 'C' started by Janice, Jan 20, 2011.

  1. Janice

    Janice New Member

    Joined:
    Jan 20, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    sir can you give me a suitable program to find the prime no. less than 10 digits,,thank you.....
     
  2. umartayyabkhan

    umartayyabkhan New Member

    Joined:
    Jan 21, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Electrical Engineering Student
    Location:
    Peshawar
    Home Page:
    You can make the counter to 10 for making it find prime no.s upto ten digits!!:pleased:

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <time.h>
    
    int is_prime(int number);
    
    
    int main(void)
    {
    
        int counter,limit;
    
        printf("Enter limit of prime numbers: ");
        scanf("%d",&limit);
        
        for (counter = 2; counter <= limit; counter++) {
    	if (is_prime(counter))
    	    printf("%d ", counter);
        }
        getch();
        return 0;
    }
    
    
    int is_prime(int number)
    {
        int divisor;
    
        for (divisor = 2; divisor <= number / 2; divisor++) {
    	if (number % divisor == 0)
    	    return 0;
        }
        return 1;
    
    }
    
    
     

Share This Page