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 types of c language?
What is a protocol in c?
Why doesnt the call scanf work?
What is the difference between NULL and NUL?
Explain what are the different data types in c?
What is the use of volatile?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
c program to compute AREA under integral
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
Where static variables are stored in memory in c?
Write a program to print ASCII code for a given digit.
What is #pragma statements?
What is spark map function?
Can we add pointers together?
Why is #define used?