一個數組有10個元素{1,8,10,2,-5,0,7,15,4,-5},利用指針作爲函數,輸出其最大值和最小值
題目:
一個數組有10個元素{1,8,10,2,-5,0,7,15,4,-5},利用指針作爲函數,輸出其最大值和最小值
解答:
int main()
{
int a[10] = {1,8,10,2,-5,0,7,15,4,-5};
int max_num = a[0];
int min_num = a[0];
for (int i = 1; i < 10; i ++)
{
if (min_num > a[i])
{
min_num = a[i];
}
else if (max_num < a[i])
{
max_num = a[i];
}
}
printf("max num = %d \n", max_num);
printf("min num = %d \n", min_num);
return 0;
}
添加新評論