Program to check for given number is prime or not

0
22
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,t=0;  /* t is using flag, during process if any number divides n, then
                    t changes to 1 */
clrscr();
printf("\n enter n\n");
scanf("%d",&n);
  if(n<=1)
    printf("\n %d is not a prime number\n",n);
  else
    {
      for(i=2;i<=n/2;++i)
      {
       if(n%i==0)
       t=1;
      }
  if(t==0)
    printf("\n %d is prime number ",n);
  else
    printf("\n %d is prime number ",n);
   }
getch();
}
  Output 1:
  enter n
  5
  5 is prime number
  Output 2:
  enter n
  68
  68 is not prime number

 

 

 

Program to check for given number is prime or not program to check given number is prime or not program to check given number is prime or not in c program to check whether a given number is prime or not program to check whether a number is prime or not program to check a number is prime or not Program to check for given number is prime or not in c Program to check for given number is prime or not in c language c Program to check for given number is prime or not prime number programĀ prime number program in c to check the given number is prime or not

LEAVE A REPLY

Please enter your comment!
Please enter your name here