-
Trouble with Factorial.
I was given a question in my programming class to create a program to find the factorial of any number greater than zero and to use Gosper's formula to approximate it. I'm not sure what I am doing wrong so any help would be appreciated!
Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double equation(int n);
int
main(void)
{
int input, double answer;
printf("Please input a number>");
scanf("%d", &input);
answer = equation(input);
printf("%d equals approximately %.2f\n", input answer);
return (0);
}
double equation(n)
{
double nfaca, nfacb, nfacc, nfacd;
nfaca = pow(n,n) * pow(e,-n);
nfacb = ((2 * n) + .33);
nfacc = sqrt(nfacb * PI);
nfacd = nfaca * nfacc;
return (answer);
}
-
Pay attention to your compiler warnings.
*You need a comma between input and answer in the printf.
*If you're going to use the constant "e" in equation, you need to define it somewhere.
*If you're going to return "answer", you need to declare it somewhere. I think you mean to return (nfact).
-
Code:
int input, double answer;
Does that compile?
Code:
int input;
double answer;