Write a C Program To Check Whether The Given Input Number Is Prime Number Or Not Using Recursion. So, The Input Is An Integer And Output Should Print Whether The Integer Is Prime Or Not. Note That You Have To Use Recursion.
Answers
Answered by
2
Answer:
/*
* C Program to find whether a Number is Prime or Not using Recursion
*/
#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);
}
}
}
Similar questions
English,
4 months ago
Math,
4 months ago
Math,
4 months ago
English,
9 months ago
Social Sciences,
9 months ago