Write a C program to determine wheather a number is prime or composite.

#include<stdio.h>
main()
{
    int n,i,f=0;
    printf("\nEnter a number=");
    scanf("%d",&n);
    if(n==1)
        printf("\n%d is neither a prime number nor a composite number",n);
    for(i=2;i<=n/2;i++)
    {
        if(n%i==0)
        {
            f=1;
            break;
        }
    }
    if(f==1)
        printf("\n%d is a composite number",n);
    else
        printf("\n%d is a prime number",n);
       
}

No comments:

Post a Comment