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

write an algorithm and c program to add two 2x2 matrics

2 Answers  


what is the difference between exit() and _exit() functions?

2 Answers  


Why #include is used in c language?

0 Answers  


What is the usage of the pointer in c?

0 Answers  


What is the purpose of the statement: strcat (S2, S1)?

0 Answers  






How can I change the size of the dynamically allocated array?

0 Answers  


1. Write a program to reverse every second word in a given sentence.

1 Answers  


#&#8206;include&#8236;<stdio.h> void main() { int i; for(i=5;0;i++) { printf("%d",i); } }

2 Answers   Facebook,


Do pointers need to be initialized?

0 Answers  


without a terminator how can we print a message in a printf () function.

7 Answers   NIIT,


What is meant by keywords in c?

0 Answers  


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?

1 Answers  


Categories