1

任何人都可以帮我处理这段代码吗?我无法弄清楚在compare_all_min ()and上使用什么参数compare_all_max ()。我的代码是:

while (count <= 10) {

    minimum = getMin ( item [count] );
    maximum = getMax ( item [count] );
    printf ( "Minimum is %d\n", &min );
    pritnf ( "Max: %d\n", &max );
    count++;
}

printf ( "Displaying summary:\n" );
least_num = compare_all_min (  );         //what argument do I  
greatest_num = compare_all_max (  );      //use on these two?
printf ( "The least number contained by the array is: %d\n", &least_num );
printf ( "The greatest number contained by the array is: %d\n", &greatest_num );

我不知道要使用什么参数,特别是因为 while 循环会打印出 10 个最小数字和 10 个最大数字。注意:基本上,compare_all_min ( )只需比较将在 while 循环中获得的所有 10 个最小值,然后获得这些值中的最小值,然后compare_all_max ( )比较所有 10 个最大值,然后获得这些数字中的最大值。非常感谢。

4

1 回答 1

1

假设您有 10 个元素,然后将数组传递给函数

int min[10]={10,2,34..};//10 numbers

least_num = compare_all_min ( min );    

带有三个数字的示例代码:

#include<stdio.h>
main()
{
int min[3]={10,2,34};//10 numbers
int least_num;
least_num = compare_all_min ( min );

printf("%d\n",least_num);
}

int compare_all_min (int *array)
{
int i,least;
least=array[0];

for(i=0;i<3;i++)
if(least > array[i])
least=array[i];
return least;

}
于 2013-09-02T11:30:43.503 回答