write a program that finds the factorial of a number using
recursion?
Answer Posted / harsha
#include<stdio.h>
#inlcude<conio.h>
unsigned int recr_factorial(int n);
unsigned int iter_factorial(int n);
void main()
{
int n,i;
long fact;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
if(n==0)
printf("Factorial of 0 is 1\n");
else
{
printf("Factorial of %d Using Recursive Function is %d\n",n,recr_factorial(n));
printf("Factorial of %d Using Recursive Function is %d\n",n,iter_factorial(n));
}
getch();
}
/*Recursive Function*/
unsigned int recr_factorial(int n);
{
return n>=1 ? n*recr_factorial(n-1):1;
}
/*Non-Recursive Function*/
unsigned int iter_Function(int n)
{
int accu=1;
int i;
for(i=1;i<=n;i++)
{
acc * =i;
}
return acc;
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are the two types of structure?
How do we make a global variable accessible across files? Explain the extern keyword?
Where does the name "C" come from, anyway?
Explain how to reverse singly link list.
What does p mean in physics?
Why is main function so important?
What is openmp in c?
what are the facialities provided by you after the selection of the student.
What is c language used for?
What is a scope resolution operator in c?
What are the advantages and disadvantages of a heap?
What is a void * in c?
Tell me is null always defined as 0(zero)?
Is Exception handling possible in c language?
What is spaghetti programming?