//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;
}
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
123
Write a program using recursion which should take two values and display 1st value raised to the power of second value.
no answer....pls post
Sure, recursion can always be substituted with using a stack.
pata nhe
Ans: Merits of recursion are: Mathematical functions, such as Fibonacci series generation can be easily implemented using recursion as compared to iteration technique. Demerits of recursion are: Many programming languages do not support recursion; hence, recursive mathematical function is implemented using iterative methods. Even though mathematical functions can be easily implemented using recursion, it is always at the cost of execution time and memory space. The recursive programs take considerably more storage and take more time during processing.
Recursion in c language is a method where the function calls itself, within or outside the scope. Using Recursion, complicated problems can be divided into smaller parts so that solving them becomes more manageable. The recursion technique is available in Java, JavaScript, and C++.serves the same purpose. The type of Recursion in C • Direct Recursion • Indirect Recursion. Direct Recursion Recursion can call the function n-number of times. In the case of direct Recursion, the function calls itself inside the same position or in the local scope Direct Recursion problems are the Fibonacci series, a program to print 50 natural numbers. Indirect Recursion In the case of Indirect Recursion, a function X calls function Y, and function Y calls any function Z. Under certain conditions, function Z calls function A. In this case, function A is indirectly related to function Z. Indirect Recursion is also known as mutual Recursion, as more than one function runs a program. It is a two-step recursive function call process for making a recursive function call. Below mentioned are also type of Recursion: Tail Recursion No Tail/Head Recursion Linear Recursion Tree Recursion Tail Recursion A function is said to be tail recursion if it calls itself and also calls the last or the previous statement executed in the process. Head Recursion A function is said to be Head Recursion if it calls itself and also calls the first or the beginning statement executed in the process. Linear Recursion A function is said to be a linear recursive function if it makes a single call to itself each time the procedure executes itself and grows linearly depending on the size of the problem. Tree Recursion Tree Recursion is different from linear Recursion. Rather than making only one call to itself, that function makes more than one recursive call to the process within the recursive function. Following are the steps to solve the recursive problem in C: Step 1: Create a function and assign the work a part should do. Step 2: Select the subproblem and assume that the function already works on the problem. Step 3: Get the answer to the subproblem and use it to resolve the main issue. Step 4: The 90% of the problem defined is solved.
No 5291 is not a prime using 2 numbers. It is a prime using three numbers.
int sum (int n) { if (n<=1) return n; else return n + sum (n-1); }
int sum(n) { if (n==0) return 0; else return n+sum(n-1); }
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
recu