Write a Program to find whether a given number is prime number or not

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,i;
    clrscr();
    printf("Enter a number \n");
    scanf("%d",&n);
    if (n<=1)
    {
    printf("Not a prime number");
    getch();
    exit();
    }
    for(i=2;i<=n/2;i++)
    {
       if (n%i==0)
       {
      printf("Not a prime number");
      getch();
      exit();
       }
    }
    printf("Its a prime number");
    getch();
}

No comments:

Post a Comment