adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

program in c to check a number is prime or not using function

program in c to check a  number is prime or not using function



#include<stdio.h>
#include<conio.h>
  int CheckPrime(int n)
  {
   int p=1,i;
   for(i=2;i<n/2;i++)
   {
    if(n%i==0)
      {
       p=0;
       break;
    }
  return (p);
    }
  }
  void main()
   {
    int n1,r;
    printf("Enter a number:-");
    scanf("%d",&n1);
    r=CheckPrime(n1);
    if(r==1)
     printf("%d is prime no.",n1);
    else
     printf("%d is not prime no.",n1);
    getch();
   }
Output:- 




Note :- When a function is declare before the main function then Function declaration (prototype of Function) is not provided. 

Post a Comment

0 Comments