#define _CRT_SECURE_NO_WARNINGS
#include
#include
void main()
{
int avg = 0;
int min_val = 0;
int max_val = 0;
int sum = 0;
int n = 0;
printf("请输入数组的大小 : ");
scanf("%d", &n);
int * arr = (int *)malloc(sizeof(int)* n);
if (NULL == arr)
{
printf("动态分配内存失败!\n");
return;
}
for (int i = 0; i < n; i++)
{
printf("请输入第%d个数字 : ", i + 1);
scanf("%d", arr + i);
sum += *(arr + i);
if (0 == i)
{
max_val = *(arr + i);
min_val = *(arr + i);
}
if (*(arr + i) > max_val)
{
max_val = *(arr + i);
}
if (*(arr + i) < min_val)
{
min_val = *(arr + i);
}
}
printf("平均值是 : %d\n", sum / n);
printf("最大值是 : %d\n", max_val);
printf("最小值是 : %d\n", min_val);
if (NULL != arr)
{
free(arr);
arr = NULL;
}
system("pause");
return;
}