任何人都可以帮我这个代码吗?我无法弄清楚在compare_all_min ()
和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个最大值值然后在这些数字中获得最大值。非常感谢。
答案 0 :(得分: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;
}