本人自学两天,编了个小程序,不知道什么地方错了。
是输入一堆数,找最大值的程序compile 可以通过,但运行时只输了一个数就停止了
#include <stdlib.h>
#include <stdio.h>
#define YES 1
#define NO 0
#define MAX 12000
int array[MAX];
int count ;
int ctr = YES;
int largest(int num_array[],int length);
void continue_function(void);
void input_function(void);
int main(void)
{
count = 0;
printf("This program finds the largest number you entered.");
do
{
input_function();
continue_function();
count++;
}while (ctr == YES);
printf("\nThe largest number you have entered is %d",largest(array,count));
system("PAUSE");
return 0;
}
void input_function(void)
{
printf("\nEnter your number:");
scanf("%d",array[count]);
}
void continue_function(void)
{
printf("Would you like to continue?");
do
{
printf("Enter 1 to continue or 0 to quit.");
scanf("%d",ctr);
}while(ctr != 1&&ctr != 0);
}
int largest(int num_array[],int length)
{
int biggest = -12000;
int nbr = 0;
for(;nbr < length; nbr++)
{
if(num_array[nbr]>biggest)
biggest = num_array[nbr];
}
return biggest;
}