一段时间以来,我一直在努力完成这项作业。而且我似乎找不到它有什么问题。
我的问题是为什么每次执行此程序时都会出现分段错误错误。
/* Description: A program that takes an input array argument with type double values and displays a table of those inputs and their absolute values.
*/
...
int main() /* Main Function */
{
/* Variables */
int size=5,n;
double value[n];
double table;
/* Instructions and Input */
for(n=0;n<size;n++){
printf("\nPlease enter value #%d:\n",n);
if(n=size-1){printf("\nPlease enter the last value.\n");}
scanf("%lf",&value[n]);
}
/* Recalling the Function and Output */
printf("\nValue\t|Value|\n"); /* Table Header */
table=abs_table(value[n],size); /*Absolute Value Table */
return 0;
}
double abs_table(double value, int size) /* Absolute Value Function */
{
int i,j; /* Counter Variables */
double v;
for(j=1;j<=size;j++){ /* For the Number of rows */
for(i=0;i<=size;i++){ /* For the number of columns */
v = abs(value); // For the absolute values */
printf("\n%g\t%g\n",value,v);
}
printf("\n"); /* To make sure the rows display on their own line */
}
return;
}