C/Small help on a program in c language
I made a program for calculating-
depending upon the number of terms user enters.
According to me the logic is correct but still i am not getting the correct output.
Here is the code for the same...
printf("enter number of terms");
int fact(int n)
A quick response regarding the reason of wrong output of the program will be appreciated.
Thanks in advance!
There were several things wrong with your code. You were using integer division to determine the value of k, which was rounded down. You should make fact return a double or cast it to a double before using it in division. To sum the result you should use k += ... or k = k + ... inside the for loop. In your recursive fact function there is no need to store the result in f when you can simply return n*fact(n-1). I hope this helps you solve your problem.
int i, n;
printf("enter number of terms:");
double fact(int n)