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 |
explain what are actual arguments?
what r the cpu registers r ther?
Differentiate b/w Modify and Update commands giving example.
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What is difference between scanf and gets?
which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }
what is the difference between global variable & static variable declared out side all the function in the file.
Is it possible to run a c program without using main?If yes HOW??
What are header files and what are its uses in C programming?
while initialization of array why we use a[][2] why not a[2][]...?