Home >Computer Tutorials >Computer Knowledge >Write a function to find the maximum value of n numbers and call it in the main function
=||
Children's shoes. . . Do you want to return the maximum value of n input numbers or the maximum value of an array? . .
Returns the function that inputs the maximum value of n numbers:
#include
int Max(int n); //Maximum function declaration
int main()
{
int n;
scanf("%d",&n); //Enter the number of numbers.
printf("the max is:%d\n",Max(n));
return 0;
}
int Max(int n)
{
int a,i,max;
scanf("%d",&max); //Assume that the first number entered is the largest
for(i=2;i
{
scanf("%d",&a);
if(a>max) //If max is smaller than the number entered later, swap
max=a; //Exchange to the end, max is the maximum value
}
return max;
}
#include
void main(){
int i,j,temp,count;
printf ("Please enter the number you need to enter:");
scanf("%d",&count);
while(count10000){
printf("The number must be between 1 and 10000!\n\n");
printf ("Please enter the number you need to enter:");
scanf("%d",&count);
}
int num[count];
for(i=0;i printf ("Please enter the %dth number:", (i 1)); scanf("%d",&num[i]); } for(i=0;i for(j=0;j if(num[j] temp=num[j]; num[j]=num[j 1]; num[j 1]=temp; } } } printf("max=%d,min=%d\n",num[0],num[count-1]); }
The above is the detailed content of Write a function to find the maximum value of n numbers and call it in the main function. For more information, please follow other related articles on the PHP Chinese website!