Pages

Monday, January 2, 2012

C Programming to decide if a number is prime or composite


/*to decide prime or composite*/
#include<stdio.h>
#include<stdlib.h>
int main( )
{
    int n,i,flag=1;
    printf ("enter number: ");
    scanf ("%d",&n);
    for (i=2; i<=n/2; i++)
    {
        if (n%i==0)
        {
            flag=0;
        }
    }
    if (flag)
        printf ("%d is prime",n);
    else
        printf ("%d is composite",n);
       
    system ("pause");
    return 0;
}

No comments:

Post a Comment