Computer Science, asked by sangeethaj2017, 4 months ago

write a c program to check a number is a prime number or not using recursion
enter number:456
456 is not a prime

Answers

Answered by pramodnagarcuraj17
1

Answer:

#include <stdio.h>

int primeno(int, int);

int main()

{

int num, check;

printf("Enter a number: ");

scanf("%d", &num);

check = primeno(num, num / 2);

if (check == 1)

{

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

}

else

{

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

}

return 0;

}

int primeno(int num, int i)

{

if (i == 1)

{

return 1;

}

else

{

if (num % i == 0)

{

return 0;

}

else

{

return primeno(num, i - 1);

}

}

}

output

Enter a number: 456

Enter a number: 456456 is not a prime number

Similar questions