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 |
Is there a way to jump out of a function or functions?
Find Index of least significant bit set in an Integer. ex. int value is say 10001000 results should be 4.
What is keyword with example?
write a program in c language for the multiplication of two matrices using pointers?
What is the need of structure in c?
Explain what is the best way to comment out a section of code that contains comments?
how write a addtion of two single dimensional array using of pointer in c language?
What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement.
main() { printf(5+"Vidyarthi Computers"); }
hi send me sample aptitude papers of cts?
how to write a program which adds two numbers without using semicolon in c
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?