Checking the given number is prime or not in C?


#include<stdio.h>

main ()
{
     int n,i,c=0;
     printf("\n\nEnter number to check :");
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
       if(n%i==0)
       {
         c=c+1;
       }
     }
     if(c==2)
     {
     printf("\nNumber is prime.");
     }
     else
     {
     printf("\nNumber is not prime.");
     }
     getch();
}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples