plz answer..... a program that reads non-negative integer
and computes and prints its factorial
Answers were Sorted based on User's Feedback
Answer / vignesh1988i
USING RECURSION
#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
int n,c;
printf("enter the non negative number :");
scanf("%d",&n);
if(n>=0)
{
c=factorial(n);
printf("the factorial is : %d",c);
}
else
printf("only for non negative numbers factorial can be
computed");
getch();
}
int factorial(int n)
{
static i=1,fact=1;
fact=fact*i;
if(i==5)
return(fact);
else
factorial(++i);
}
iam back thank you
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / valli
//using recursion
fact(int);
main()
{
int n;
printf("enter n");
scanf("%d",n)
if(n<0)
printf("invalid number");
else
printf("factorial of %d =%d",n,fact(n));
}
fact(int n)
{
if(n==0||n==1)
return 1;
else
return n*fact(n-1);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Hai friends im a i year student. i want to develop my knowledge in the field of TSR in c. How I'm Improve ?
Why can't we initialise member variable of a strucutre
Why we use stdio h in c?
what is used instead of pointers in java than c?
Write a program of prime number using recursion.
What is the difference between functions abs() and fabs()?
find the size of structure without using the size of function
If you know then define #pragma?
What is a nested loop?
What is hungarian notation? Is it worthwhile?
Is c easy to learn?
Why is c used in embedded systems?