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 |
write an algorithm and c program to add two 2x2 matrics
what is the difference between exit() and _exit() functions?
Why #include is used in c language?
What is the usage of the pointer in c?
What is the purpose of the statement: strcat (S2, S1)?
How can I change the size of the dynamically allocated array?
1. Write a program to reverse every second word in a given sentence.
#‎include‬<stdio.h> void main() { int i; for(i=5;0;i++) { printf("%d",i); } }
Do pointers need to be initialized?
without a terminator how can we print a message in a printf () function.
What is meant by keywords in c?
You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?