c program to manipulate x=1!+2!+3!+...+n! using recursion
Answer Posted / 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 View All Answers
How variables are declared in c?
C language questions for civil engineering
Explain Basic concepts of C language?
What are dangling pointers in c?
Can 'this' pointer by used in the constructor?
What are 3 types of structures?
What is the need of structure in c?
what are non standard function in c
What are the advantages of using linked list for tree construction?
Difference between strcpy() and memcpy() function?
Is that possible to store 32768 in an int data type variable?
What is string constants?
write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values. The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.
What is a volatile keyword in c?
Here is a good puzzle: how do you write a program which produces its own source code as output?