Program to Check given number is prime number or not using Recursion

C Program to Check given number is prime number or not using Recursion

This page has C Program to Check given number is prime number or not using Recursion. Prime numbercan be checked by using recursion. The recursion is a process which call the function itself. A few Prime number examples: 5,  11, 17, 23, 19, 29, 3, 37, 43, 7, 53. The below given C program to Check given number is prime number or not using Recursion. In this page, I have used a recursion technique to check a number whether it belongs prime or not. Kindly check out the programs to Check a given number is prime number or not using Recursion.


Program to Check given number is prime number or not using Recursion


  #include<stdio.h>
  int prime(int, int);
          int main(){
          int np,remcheck=1;
          clrscr();
          printf("Give a Positive whole number : \n");
          scanf("%d", &np);
          remcheck = prime(np, np/2);
          if(remcheck==1)
          printf("The Entered Number %d is Prime",np);
          else
          printf("The Entered Number %d is not Prime",np);
          getch();
          return(0);
          }

  int prime(int npf, int maxfind){
          if(maxfind == 1)
          return(1);
          else
          {
          if(npf % maxfind == 0)
          return(0);
          prime(npf, maxfind-1);
          }
          }


Sample output:

Give a Positive whole number :  53

The Entered Number 53 is Prime

Give a Positive whole number :  26

The Entered Number 26 is not Prime  


Related Popular Posts:

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share