Input array index N 輸入數組索引
Input the number of N 輸入氮的數目
Print the maximum value and the minimum value 打印最大值和最小值
代碼如下:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i,index,min,max;
int *numbers;
printf("Input array index : ");
scanf("%d" , &index);
if(index != 0)
{
numbers = (int *)malloc(index*sizeof(int));
}
if(NULL == numbers)
{
return 1;
}
printf("Input 5 numbers : ");
for(i = 0 ; i < index ; scanf("%d",&numbers[i]),i++);
for( i = 0 ,min = max = numbers[0] ; i < index ; i++)
{
if(min > numbers[i])
{
min = numbers[i];
}
if(max < numbers[i])
{
max = numbers[i];
}
}
printf("maximum : %d\nminimum : %d\n",max,min);
return 0;
}