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

what is pointer ?

10 Answers   Kernex Micro Systems,


How can you increase the size of a statically allocated array?

0 Answers   TISL,


How can I list all of the predefined identifiers?

0 Answers  


Why c is known as a mother language?

0 Answers  


If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402

0 Answers  






Explain what is the benefit of using enum to declare a constant?

0 Answers  


#include<stdio.h> int SumElement(int *,int); void main(void) { int x[10]; int i=10; for(;i;) { i--; *(x+i)=i; } printf("%d",SumElement(x,10)); } int SumElement(int array[],int size) { int i=0; float sum=0; for(;i<size;i++) sum+=array[i]; return sum; } output?

5 Answers   Ramco,


how to set Nth bit of a variable?

1 Answers  


How do I access command-line arguments?

2 Answers   Bosch, Wipro,


what is the advantage of using SEMAPHORES to ORDINARY VARIABLES???

2 Answers   NSN,


What is the difference between declaring a variable by constant keyword and #define ing that variable?

1 Answers  


An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

0 Answers  


Categories