Home >Computer Tutorials >Computer Knowledge >Write a function to find the maximum value of n numbers and call it in the main function

Write a function to find the maximum value of n numbers and call it in the main function

王林
王林forward
2024-01-25 09:24:171208browse

Write a function to find the maximum value of n numbers and call it in the main function

The function of writing a function is the maximum value of n numbers. Call the function in the main function to implement

=||

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;

}

C language inputs N numbers and outputs the maximum and minimum values

#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!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete