Thursday, 2 December 2010

test a function for a no is prime no or not?

//test a no is prime no or not
#include<stdio.h>
#include<conio.h>
#define TRUE 1
#define FALSE 0
int prime(int n)
{
 int i;
 for(i=2;i<=n/2;i++)
 {
  if(n%i==0)
   return(FALSE);

 }
 return(TRUE);
 }
void main()
{
 int n,prime(int );
 printf("ener any number\n");
 scanf("%d",&n);
 if(n<2)
  printf("invalid numpber\n");
 if(prime(n))
  printf("prime no\n");
 else
  printf("not a prime number\n");
  getch();
 }
c programs

No comments:

Post a Comment