Tuesday 5 September 2017

C-Program to know whether given number is Prime or Not



#include<stdio.h>

int main()
{
  int num,i,count=0;
  printf("Enter a number to check whether it is prime or not\n");
  scanf("%d",&num);
        for(i=1;i<=num;i++)
      {
         if(num%i==0)
         {
           count++;
         }
     }
         if(count==2)
        {
               printf("The given number %d is Prime Number\n",num);
        }
       else
       {
         printf("The given number %d is not Prime Number\n because The number is     divisible by\n",num);
            for(i=1;i<=num;i++)
            {
                if(num%i==0)
               {
                    printf("%d\n",i);
               }
           }
       }
return 0;
}

No comments:

Post a Comment