Chapter:

Recursive-program-in-c

C Program to find wher a Number is Prime Or Composite using Recursion

Prime Number: A number that is only divisible by 1 and itself.

Composite Number: A number that is not a prime number.

Note: 1 is neither prime nor composite.

Below is a program to find whether the user input number is a prime number or a composite number using recursion.

Source code:

#include<stdio.h>


// declaring the recursive function

int isPrime(int, int);


int main()

{

    int num, prime;

    printf("Enter a positive number to check if Prime: ");

    scanf("%d", &num);

    prime = isPrime(num, num/2);

    if(prime == 1)

    {

        printf("\n\n%d is a prime number\n\n", num);

Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-