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