DarkWebCode is a place where you can find a lot of exciting and inspiring stuff about Web Development, Blogging, SEO and many more

Breaking

C program to check the prime number

AIM : 
             To write a C program to check the prime number.

ALGORITHM :
     
                 1.Start
                 2.Read n.
                 3.From i=2 to n/2 divide the number by i.
                 4. if the number is divisible by any other numbers then that number is not prime.
                 5.if the number is not divisible by any other numbers then that number is prime.
                 6.Display the result.
                 7.Stop.

PROGRAM : 

#include<stdio.h>
#include<conio.h>
void main()
{
           int i,n,count;
           count=0;
           printf("Enter n value: ");
           scanf("%d",&n);
           for(i=2;i<=n/2;i++)
           {
                if(n%i==0)
                {
                     count++;
                 }
             }
             if(count==0)
                 {
                      printf("Prime")
                  }
              else
                  {
                      printf("Not prime");
                   }
   getch();
}