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

Program to find prime numbers

Discussion in 'C' started by avashist0@rediff.com, Jan 10, 2011.

  1. avashist0@rediff.com

    avashist0@rediff.com New Member

    Joined:
    Jan 10, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Sir
    can you please give me a suitable program to find prime number less than 100????
     
  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:
    Is this u r looking 4?

    Code:
    #include <stdio.h>
    int is_prime(int number);
    int main(void)
    {
    
        int counter,limit;
    
        
        
        for (counter = 2; counter <= 100; 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