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);
,這裏是我的輸出
你分配一個整數數組並將其分配給一個雙指針。 –