write a program that finds the factorial of a number using
recursion?
Answers were Sorted based on User's Feedback
Answer / abhinandan
#include<stdio.h>
main()
{
int a, fact;
printf("\nEnter any number: ");
scanf ("%d", &a);
fact=rec (a);
printf("\nFactorial Value = %d", fact);
}
rec (int x)
{
int f;
if (x==1)
return (1);
else
f=x*rec(x-1);
return (f);
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / 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 |
Answer / priyanka
# include <stdio.h>
main()
{
int n,f,fact;
clrscr();
printf("Enter a no.....");
scanf("%d",&n);
f=fact(n);
printf("Factorial is :%d",f);
}
int fact(int n)
{
if(n<=1)
return 1;
else
n=n*fact(n-1);
return n;
}
getch();
Is This Answer Correct ? | 0 Yes | 1 No |
how can i sort numbers from ascending order and descending order using turbo c..
Which is better oop or procedural?
Explain how can I avoid the abort, retry, fail messages?
What is the meaning When we write "#include" what is # and what does include does there???
How can I remove the trailing spaces from a string?
Differentiate between #include<...> and #include '...'
how to print value of e(exp1)up to required no of digits after decimal?
Give differences between - new and malloc() , delete and free() ?
1)what is the error in the following stmt where str is a char array and the stmt is supposed to traverse through the whole character string str? for(i=0;str[i];i++) a)There is no error. b)There shud be no ; after the stmt. c)The cond shud be str[i]!='\0' d)The cond shud be str[i]!=NULL e)i shud be initialized to 1
main() { float f1=10.5; double db1=10.5 if(f1==db1) printf("a"); else printf("b") }
write a program to print the all 4digits numbers & whose squares must me even numbers?
write a c program to find largest number in matrix(in each row,each column, diagonally, and in the whole matrix)? Its urgent.