Prime Number Program in C - C program to find prime numbers



 c program to find prime numbers

Learn C - C tutorial - c program to find prime numbers - C examples - C programs

C program to find prime numbers

  • A Prime Number can be divided only by 1, or itself.
  • Every natural number is either a prime or can be expressed as a multiple of a prime.
  • All primes except the number 2 are odd numbers, because all other even numbers are multiples of 2.

Sample Code

#include<stdio.h>
int main()
{
    int num,i,count,n=9;
    printf("Max range:9");
    for(num=1; num<=n; num++)
    {
        count = 0;
        for(i=2; i<=num/2; i++)
        {
            if(num%i==0)
            {
                count++;
                break;
            }
        }
        if(count==0 && num!= 1)
            printf("\n%d ",num);
    }
    return 0;
}

Output

Max range:9 
2 
3 
5 
7 


View More Quick Examples


Related Searches to Prime Number Program in C - C program to find prime numbers