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
Is there any data type in c with variable size?
Why do we need arrays in c?
Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?
What is string in c language?
How do I get a null pointer in my programs?
How do I convert a string to all upper or lower case?
hi send me sample aptitude papers of cts?
What is variable initialization and why is it important?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
What is pass by reference in functions?
Write a program to print numbers from 1 to 100 without using loop in c?
What are the two types of structure?
Process by which one bit pattern in to another by bit wise operation is?
Write a program that accept anumber in words
Explain how can you avoid including a header more than once?