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 is break in c?
What is a macro, and explain how do you use it?
How can I get back to the interactive keyboard if stdin is redirected?
How can I trap or ignore keyboard interrupts like control-c?
What are structure members?
can any one provide me the notes of data structure for ignou cs-62 paper
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
What is c language in simple words?
What is character set?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What is a loop?
What are qualifiers in c?
What are the valid places to have keyword “break”?
What is the use of a conditional inclusion statement in C?
What does dm mean sexually?