C初学者在这里,我有一个程序,我正在处理,不幸的是,该程序要么不正确地读取数组,要么不正确地显示内容。数组内容显示不正确
这里就是我有
int main()
{
int size; // the number of elements
printf("Enter size of the array: \n");
scanf("%d", &size);
double *array = malloc(size*sizeof(int)); //memory allocated using malloc
if (array == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements of array: \n");
for (int i = 0; i<size; ++i)
{
scanf("%d", &array[i]);
}
printf("Results:");
double min = array[0];
printf("\nmin = %.3lf ", min);
double max = array[size - 1];
printf("\nmax = %.3lf", max);
,这里是我的输出
你分配一个整数数组并将其分配给一个双指针。 –