Dark Horse programmer------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------
A function definition
01 functions are divided into library functions and custom functions.
Function General format:
The function returns a value type function name (data type parameter 1, data type parameter 2, ...)
{
function body;
}
* If the function does not need to return a value type, it is represented by void
* The mark of the function is the parentheses, regardless of the parameters, the parentheses exist
* When defining a function, you should not add a semicolon after the closing parenthesis
* Do not define the variables that appear in the parameter list again in the function list
* Multiple parameters are separated by commas, even if the data type is the same, it cannot be declared at the same time, that is, the data type and parameters must appear in pairs
//expression k!/(m!+n!) The value#include<stdio.h>DoubleFactintf) { inti; DoubleR =1; for(i=1; i<f;i++) {R= r*i; returnR; }}intMain () {intK,m,n; Doublef1,f2,f3; printf ("Please enter a three integer: \ n"); scanf ("%d%d%d",&k,&m,&N); F1=fact (k); F2=fact (m); F3=fact (n); printf ("k!/(m!+n!) =%f\n", f1/(f2+f3)); }
Two function calls
01 general form of function invocation:
function name (actual parameter table) if the called function has no arguments, the "actual parameter table can be empty"
02 parameter passing between functions
The rules of C are simple, all the parameters of the C-language function are passed in the "call-to-value" mode, and the parameter passing direction is always passed to the formal parameter.
03 Return value of function
return expression;
The function of the return statement is to immediately end the execution of the current function and return to the keynote function.
//enter two integers to calculate their average, requiring the calculation of the average value with a function#include<stdio.h>DoubleAverageintXinty);intMain () {intb; Doubleresult; printf ("Please enter a two integer: \ n"); scanf ("%d%d",&a,&b); Result=average (A, b); printf ("the average of%d and%d is%f\n", A,b,result); return 0;}DoubleAverageintXinty) { DoubleAve; Ave= (x+y)/2; returnAve;}
09-Dark Horse Programmer------C language Learning notes---C language functions