帮帮小女
我刚学的c语言 对这个程序很不了解 谁能帮我每一步都解释一下呢~? 谢谢拉~
/* Passing an array to a function. */
#include <stdio.h>
#define MAX 10
int array[MAX], count;
int largest(int num_array[], int length);
int main( void )
{
/* Input MAX values from the keyboard. */
for (count = 0; count < MAX; count++)
{
printf("Enter an integer value: ");
scanf("%d", &array[count]);
}
/* Call the function and display the return value. */
printf("\n\nLargest value = %d\n", largest(array, MAX));
return 0;
}
/* Function largest() returns the largest value */
/* in an integer array */
int largest(int num_array[], int length)
{
int count, biggest = -12000;
for ( count = 0; count < length; count++)
{
if (num_array[count] > biggest)
biggest = num_array[count];
}
return biggest;
}
----------------解决方案--------------------------------------------------------
/* Passing an array to a function. */
#include <stdio.h>
#define MAX 10
int array[MAX], count;
int largest(int num_array[], int length); /*声明函数*/
int main( void )
{
/* Input MAX values from the keyboard. */
for (count = 0; count < MAX; count++) /*该循环将数值输入到数组中*/
{
printf("Enter an integer value: ");
scanf("%d", &array[count]);
}
/* Call the function and display the return value. */
printf("\n\nLargest value = %d\n", largest(array, MAX)); /*输出largest函数返回的值*/
return 0;
}
/* Function largest() returns the largest value */
/* in an integer array */
int largest(int num_array[], int length) /*该函数功能是将num_array数组中的最大值找出并返回*/
{
int count, biggest = -12000; /*定义一个biggest变量存放最大值*/
for ( count = 0; count < length; count++)
{
if (num_array[count] > biggest) /*如果num_array[count] 比biggest还大就将num_array[count] 赋给biggest*/
biggest = num_array[count];
}
return biggest;
}
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽