//Program to check number is prime or not using recursive function
#include<stdio.h>
#include<stdlib.h>
void prime(int num,int count)
{
if(count<num)
{
if(num%count==0)
{
printf("%d is not Prime number\n",num);
goto exit;
}
count += 1;
if(count<num)
{
prime(num,count);
}
}
if(num==count)
{
printf("%d is a Prime Number\n",num);
}
exit:
return 0;
}
int main()
{
system("cls");
int gvar;
printf("Enter the number = ");
scanf("%d",&gvar);
prime(gvar,2);
printf("\nashokakhil@gmail.com\n");
system("PAUSE");
return 0;
}
I think this can be another solution
#include<stdio.h>
#include<conio.h>
int prime(int);
main()
{
int i=1,r;
clrscr();
r=prime(i);
if(r==1)
printf("\n\n\tNo is prime ");
getch();
}
int prime(int i)
{
int n=1,ans,flag=1;
i++;
ans=n%i;
if(ans==0)
{
printf("\t\t\n\nNo is not prime");
flag=0;
return flag;
}
if((i!=n-1)&&(n!=1))
flag=prime(i);
return flag;
}
Chat with our AI personalities
Write a program using recursion which should take two values and display 1st value raised to the power of second value.
Sure, recursion can always be substituted with using a stack.
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
A flowchart for factorial of number can be made using different software's. Microsoft Word is the most popular software for beginners to make simple flowcharts.In order to draw the flowchart write the number at the top of the paper and then draw two lines under it going slightly to the sides. Decide what two numbers can be multiplied to equal that number. Keep going until you can no longer get to smaller numbers.
the Taylor series of sinx