小编Joh*_*ine的帖子

为什么这两个C程序不会产生相同的结果?

我首先写了这个程序,它递归地计算pi并在误差值足够小时停止.

 #include <stdio.h>`
 #include <stdlib.h>
 #include <math.h>

int threads=1;
double error=0.000001;
double func(double);


struct args{
         double l;
         double r;
         double fl; 
         double fr; 
         double area;};

double quad(struct args*);

int main(int argc, char *argv[]) {

    struct args* res = (struct args*)malloc(sizeof(struct args));
    res->l=0;
    res->r=1;
    res->fl=1;
    res->fr=0;
    res->area=0;

    double ans=quad(res);
    free(res);

    ans=ans*4;

    printf("pi=%f\n",ans);


}


double func(double x){
        x=(1-(x*x));
        x=sqrt(x);
        return x;
    }


double quad(struct args* arg){
    double m=(arg->l+arg->r)/2;
    double fm=func(m);
    double larea=(arg->fl+fm)*(m-arg->l)/2;
    double rarea = (fm+arg->fr)*(arg->r-m)/2;

    struct args* arg1 = (struct args*)malloc(sizeof(struct …
Run Code Online (Sandbox Code Playgroud)

c debugging void-pointers

3
推荐指数
1
解决办法
94
查看次数

检查 Python 脚本是否使用另一个 Python 脚本编译

我知道py_compile.compile("file.py")会编译file.py。

但是我可以在运行该命令的同一代码中以某种方式检查编译是否成功吗?

我想基本上有一个 if 条件,具体取决于编译是否成功。是否可以使用 py_compile 模块?或者我可以使用更好的东西吗?

python compilation python-3.x

2
推荐指数
1
解决办法
208
查看次数

在clojure中,我如何选择并返回集合的子集

如果我有这样的集合

{{:A "a" :B "b"} {:A "a" :B "Goal" } {:A "a" :B "Goal"}}
Run Code Online (Sandbox Code Playgroud)

如何创建一个函数,只返回部分在哪里:B "Goal"?仅含义:

{{:A "a" :B "Goal" } {:A "a" :B "Goal"}}
Run Code Online (Sandbox Code Playgroud)

collections clojure

0
推荐指数
1
解决办法
72
查看次数