程序“读取”非负整数并填充MAX大小为100的数组,直到填充或用户给出-1。然后,函数范围查找最小值和最大值并将它们“发送”到程序。例如,如果用户给出67 54 78 85 -1,则值的范围是54-85。
问题是,main不打印范围。而是显示:“值的范围是2-24576000”
#include <stdio.h>
#include "simpio.h"
int read_data(int A[]);
void range(int sum,int A[100], int *r1, int *r2);
int main()
{
int A[100], sum, max, min,i;
int *r1,*r2;
r1 = &max;
r2 = &min;
printf("Enter the elements of the array, one per line.\n");
printf("Use -1 to signal the end of the list.\n");
sum=read_data(A);
range(sum,A, &max, &min);
printf("The number of elements is: %d\n",sum);
printf("The range of values is %d - %d",min ,max);
}
int read_data(int A[])
{
int i,sum,value;
sum=value=i=0;
while ( i<100 && value !=-1)
{
printf("? ");
value = GetInteger();
if (value != -1)
{
A[i] = value;
value = A[i];
sum+=1;
}
i++;
}
return sum;
}
void range(int sum,int A[100], int *r1, int *r2)
{
int i,max,min;
max =0;
min = 32767;
*r1 = min;
*r2 = max;
for(i=0;i<sum;i++)
{
if (A[i]!=-1)
{
if (A[i]>max)
max = A[i];
if (A[i]<min)
min = A[i];
}
}
*r1 = max;
*r2 = min;
}