Powered By Blogger

Friday, December 24, 2010

C Program to check if a number is a prime number or not

/* C Program to check whether the entered number is prime or not */

#include <stdio.h>

int main()
{
    int num;
    int ctr;
    int count=0;

    printf("Enter the number\n");
    scanf("%d",&num);

    for(ctr=2;ctr<num;ctr++)
    {
        if((num%ctr)==0)
        {
            count++;
        }
    }

    if(count==0)
    {
        printf("The number is a prime number\n");
    }
    else
    {
        printf("The number is not a prime number\n");
    }

    return 0;
}



No comments:

Post a Comment