plz answer..... a program that reads non-negative integer
and computes and prints its factorial

Answers were Sorted based on User's Feedback



plz answer..... a program that reads non-negative integer and computes and prints its factorial..

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

plz answer..... a program that reads non-negative integer and computes and prints its factorial..

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

Post New Answer

More C Interview Questions

Hai friends im a i year student. i want to develop my knowledge in the field of TSR in c. How I'm Improve ?

2 Answers  


Why can't we initialise member variable of a strucutre

1 Answers  


Why we use stdio h in c?

0 Answers  


what is used instead of pointers in java than c?

1 Answers   Vuram,


Write a program of prime number using recursion.

0 Answers   Aspiring Minds,


What is the difference between functions abs() and fabs()?

0 Answers  


find the size of structure without using the size of function

1 Answers   Bosch,


If you know then define #pragma?

0 Answers  


What is a nested loop?

0 Answers  


What is hungarian notation? Is it worthwhile?

0 Answers  


Is c easy to learn?

0 Answers  


Why is c used in embedded systems?

0 Answers  


Categories