Header Ads

Header ADS

Write a program to find whether a number N is prime or not using recursive function, where N is a positive number given by the keyboard.

 Write a program to find whether a number N is prime or not using recursive

function, where N is a positive number given by the keyboard:


#include<stdio.h>

int primeNotprime(int n,int i){

    if(i<n){

        if(n%i==0){

            return 0;

        }

        primeNotprime(n,i+1);

    }

    else


     return 1;

}

int main(){

    int num,temp;

    scanf("%d",&num);

    temp=primeNotprime(num,2);

    switch(temp){

        case 1:

            printf("\nPrime\n");

            break;

        default:

            printf("\nNot Prime\n");

    }

}


No comments

Powered by Blogger.