I wrote this code that checks whether a number is prime or not. It returns 1 if the number is prime or 0 otherwise. U just look at the bottom of the code...
#include<stdio.h>
#include<conio.h>
#include<assert.h>
int is_prime(int n);
void main(void)
{
int n=0;
clrscr();
printf("An integer ");
scanf("%d",&n);
assert(n > 1);
n=is_prime(n);
if (n==1)
printf("\nThe number is prime");
else
printf("\nThe number is NOT a prime");
getch();
}
int is_prime(int n)
{
int i;
for(i=2;i<n;i++){
if (n%i) continue;
else return 0;
}
return 1;
}
But againnnnn... i want to know how can i convert the iterative version into a recursive one. Will anyone help me convert this prime checking function into a recursive one?