c program to manipulate x=1!+2!+3!+...+n! using recursion



c program to manipulate x=1!+2!+3!+...+n! using recursion..

Answer / satya

#include<stdio.h>
#include<conio.h>
int sumfact(int n)
{ int cnt=0,out;
if(cnt==0)
out=1;
if(n==1)
return out;
else
{
int i,fact=1;
for(i=n;i>=2;i--)

fact*=i;
out+=fact;
cnt++;

return out+sumfact(n-1);
}
}
main()
{
int out,n;
clrscr();
printf("Enter the vlue of n ");
scanf("%d",&n);
out=sumfact(n);
printf("%d",out);
getch();
}

Is This Answer Correct ?    6 Yes 6 No

Post New Answer

More C Interview Questions

Why c is called object oriented language?

0 Answers  


what is the difference between while and do while?

2 Answers  


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

2 Answers   Facebook,


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

0 Answers  


#include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); } what is the output for this?

4 Answers   IIIT,






What does it mean when the linker says that _end is undefined?

0 Answers  


Is c an object oriented programming language?

1 Answers  


What is the c value paradox and how is it explained?

0 Answers  


How do i store a paragraph into a string? for example, if i input a long paragraph, the program will read the words one by one and concatenate them until no word is left.

1 Answers  


what will be the output for the following main() { printf("hi" "hello"); }

5 Answers   RoboSoft,


Is fortran faster than c?

0 Answers  


main() { int i=0; while(+(+i--)!=0) i-=i++; printf(i); }

3 Answers  


Categories