必承其重 | 欲带皇冠 2018-10-22 22:53 采纳率: 0%
浏览 385

为什么我的命令窗口在传递标记时显示一个总线错误?

I'm currently working on a school project where we are required to do some sequencing, but in my code however I am getting a bus error while running the double precision but not the single precision.

#include <stdio.h>
#include <string.h>

void singleprecision()
{
    float x[21];
    x[1] = 11.0f/2.0f; x[2] = 61.0f/11.0f;

    int k = 3;
    for (; k <= 10; k++)
    {
        x[k] = 111.0f-(1130.0f - 3000.0f/x[k-2])/x[k-1];
        printf("x[%d]:%f\n",k,x[k]);
    }
}



void doubleprecision()
{
    double x[21];
    x[1]=11.0/2.0;
    x[2] = 61.0/11.0;

    int k = 3;
    for(; k<=20; k++);
    {
        x[k] = 111.0 - (1130.0 - 30000.0/x[k-2])/x[k-1];
        printf("x[%d]:%lf\n",k,x[k]);
    }
}


int main(int argc, char *argv[])
{ 
    int i = 0; // will there be double precision used based on the g input in the command line

    if (argc == 2 && strcmp(argv[1],"-d")==0) // checking for -g input on the command line
    {
        doubleprecision();
        printf("Double Precision is being used \n");
    }
    else 
    {
       printf("Single Precision is being used \n");
       singleprecision();
    }

   return 0;
}

Any help would be wonderful in order to assist me in getting through this challenge and understanding it.

I am running on a remote linux system and compiling with gcc, it compiles fine but likewise fails when in double precision.

转载于:https://stackoverflow.com/questions/52938764/why-does-my-command-window-present-a-bus-error-while-passing-a-tag-through

  • 写回答

1条回答 默认 最新

  • larry*wei 2018-10-23 00:25
    关注

    in the function: doubleprecision() remove the extraneous ; from the end of the statement: for(; k<=20; k++) Then the code runs with no problems.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog