最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

math - Attempting to implement the gamma function in C - Stack Overflow

programmeradmin3浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论