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 |
code snippet for creating a pyramids triangle ex 1 2 2 3 3 3
Write a program to generate prime factors of a given integer?
When should a type cast be used?
write a program to print calender using for loop.
What are the different types of control structures?
write a program in C to swap two variables
What is volatile variable in c with example?
Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
main() { int i=0; while(+(+i--)!=0) i-=i++; printf(i); }
How can I read data from data files with particular formats?
write a C program, given number is double without using addt ion and multiplication operator?ex:n=6,ans=12,pls send me ans to goviseenu@gmail.com
how to set Nth bit of variable by using MACRO