Verification of a given number if prime or not

Program Description

Accepts a value from user and checks whether the given number is a prime number or not using function.

*  Verification of a given number if prime or not

//function prototype
int prime(int no);

int main()
   int num,ans;
   //taking user input
   printf("\nEnter the number : ");
   ans = prime(num);
    printf("\nPrime Number\n");
    printf("\nNot a Prime Number");
   return 0; 


Function definition for prime function

Function: prime() .The function takes a single integer number and
          cheack whether the number is prime or not
Input  : Takes a single integer as argument,which is to be verified.

Return : The function returns 
          1-> if the given number is prime
          0-> if the given number is not prime		  

int prime(int no)
   int i;
      return 0;  //not a prime number
   //prime number
     return 1;

Test Case 1:

Enter the number : 24
Not a Prime Number
Test Case 2:

Enter the number : 47
Prime Number
Test Case 3:

Enter the number : 49
Not a Prime Number

comments powered by Disqus