沉默的人e 发表于 2020-3-7 11:35:16

C语言在JupyterNotebook中的问题

本帖最后由 沉默的人e 于 2020-3-25 18:37 编辑

向大伙请教请教C语言在JupyterNotebook中发生的问题,
在C语言中导入math.h库,用到了sqrt()这个函数
问题在于,sqrt函数里面的参数如果是个变量,就会出现这个情况,咋回事?

https://imgchr.com/i/3OxOeJ

如果是常量就没事

https://imgchr.com/i/3OzAwd

比较急,因为下周开始上网课了
在此先谢谢各位大佬

墨羽岚 发表于 2020-3-7 11:39:30

本帖最后由 墨羽岚 于 2020-3-7 11:49 编辑

emmm我代码和你一样但是成功输出了正确答案{:10_277:}

沉默的人e 发表于 2020-3-7 12:10:29

我的是用
jupyter notebook
写的,能不能是软件哪里出了什么问题

Cool_Breeze 发表于 2020-3-7 14:20:32

本帖最后由 Cool_Breeze 于 2020-3-7 14:24 编辑

没有问题Dev_C++ 5.11
.c#include <stdio.h>
#include <math.h>
int main(void)
{
        double i=10;
        printf("%0.15f\n",sqrt(i));
        printf("%s\n",__TIME__);
        return 0;
}


3.162277660168380
14:19:08

--------------------------------
Process exited after 0.009925 seconds with return value 0
请按任意键继续. . .

沉默的人e 发表于 2020-3-7 16:46:31

我说的就是JupyterNotebook 上的问题
这个软件我们必须要用,
所以还请大佬帮个忙

1812099418 发表于 2020-3-10 14:24:09

.

__墨鱼卷__ 发表于 2020-3-23 16:29:06

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

void main()
{
        const int o = 3;
        float c = sqrt(double(o));
        printf("%f\n", c);

        system("pause");
}

试试const int o = 3;
结果:
1.732051
请按任意键继续. . .

__墨鱼卷__ 发表于 2020-3-23 16:36:48

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

void main()
{
      const int o = 3;
      float c = sqrt(double(o));
      printf("%f\n", c);

      system("pause");
}

结果
1.732051
请按任意键继续. . .

沉默的人e 发表于 2020-3-23 20:27:35

本帖最后由 沉默的人e 于 2020-3-23 20:29 编辑

劳烦各位,已经解决
在第一行加入以下内容
//%cflag: -lm

沉默的人e 发表于 2020-3-25 18:37:56

问题已自行解决,请上头删帖
稍后发帖分享
页: [1]
查看完整版本: C语言在JupyterNotebook中的问题