C language introduction tutorial – -10 functions

A function is a group of statements that perform a task together. Every C program has at least one function, the main function (), and all simple programs can define additional functions.

Functions are pieces of functionality that are put together for easy reuse.

The /* function returns the larger of the two numbers */
 int max(int num1, int num2) 
{ 
/* Local variable declaration */ 
int result; 
if (num1 > num2) 
result = num1;
else result = num2; 
return result; 
}

int main(a)
{
	int c = max(4.6);
	int d = max(100.1000);
	printf("Group 1 Max :%d\n",c);
	printf("The second maximum is :%d\n",d);
	return 0;
}
Copy the code

Running results:



We write the maximization as a function so that we can reuse it easily.



1: The first int is the return type, void if there is no return argument

2: Max is the function name

3: num1 and num2 are arguments to the function.

So let’s think about the problem set: find the minimum of three numbers. Practice more yourself, you can be more proficient.