I am implementing the gamma function in C.
#include <stdio.h>
#include <math.h>
#define RHS 1000
#define STEP_SIZE 0.01
double gamma(double z){
double result = 0;
double t;
for(t = STEP_SIZE; t < RHS; t += STEP_SIZE){
result += pow(t, z)*exp(-t)*STEP_SIZE;
}
return result;
}
int main() {
// Write C code here
printf("%f\n", gamma(10));
printf("%f\n", gamma(0.5));
return 0;
}
I achieved this by fiddling around. Why does this work?