Prime number in C language

 WAP to check whether the entered number is prime or not.


#include<stdio.h>

#include<conio.h>

void main()

{

  int num,i,f=0;

  clrscr();

  printf("\n Enter any number :");

  scanf("%d",&num);

  for(i=1;i<=num;i++)

  {

   if(num%i==0)

    f++;

  }

  if(f==2)

   printf("\n Input number is prime");

  else

   printf("\n Input number is not prime");

  getch();

}


Output:-

Enter any number

7

Input number is prime

Post a Comment

0 Comments