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 |
what does data structure mean?
What is the difference between ++a and a++?
Who developed c language?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)
Write a program using bitwise operators to invert even bits of a given number.
If null and 0 are equivalent as null pointer constants, which should I use?
write a program wch produces its own source code aas its output?
Describe advantages and disadvantages of the various stock sorting algorithms
Eight queens puzzle
What are enumerated types?
to write a program, that finds the minimum total number of shelves, including the initial one, required for this loading process. The packets are named A, B, C, D, E …….. Any numbers of packets with these names could be kept in the shelf, as in this example: [ZZLLAAJKRDFDDUUGGYFYYKK]. All packets are to be loaded on cars. The cars are lined in order, so that the packets could be loaded on them. The cars are also named [A, B, C, D, E,………….].
Is there any book to know about Basics of C Language?