Become Our Fan on Social Sites!

Facebook Twitter

Google+ RSS YouTube

Sunday, 22 September 2013

Prime Number Program : Find Prime Number Using C Language

Prime Number : A positive number which is divisible by 1 and number itself is knows as prime number.

For example 7 is prime number because it is divisible by only 1 and number itself(7). While 14 is not prime because it is divisible by 1,2,7, and 14 itself. 

Following is a program of prime numbers in c language:



#include<stdio.h>

int main()
{
    int no, i, flag=0;
    printf("Enter No : ");
    scanf("%d",&no);

    for(i=2; i<=no/2; i++)
    {
        if(no%i == 0)
        {
            flag = 1;
            break;
        }
    }
    if(flag == 1)
        printf("Not Prime");
    else
        printf("Prime");
   
    return 0;
}

0 comments :

Post a Comment