One-shape participation Argument
1). define
Formal Parameter: Formal Parameters.
When defining a function, the parameter that is written at the back of the Letter's parentheses is called the formal argument
arguments: actual Parameters.
When calling a function, the argument that is written after the Function's parentheses is called the Arguments.
2). Note
A. An argument can be either a constant, a variable, or an expression; a formal parameter: it can actually be understood as a local variable of the Function.
B. Argument-to-parameter values, in fact, is equivalent to assigning a parameter (local Variable) to a function
C. Value passing: changes the value of a parameter within a function without affecting the outside argument
D. in the C language, all types, except arrays, are passed value as argument passing
Two-parameter function
function definition syntax with parameters:
void function name (type parameter Name) {
function body;
}
Application Scenario: When a function has to pass some data to the outside of a function, use parameters
Tips: code examples are as follows
#include <stdio.h>
/*
* Determine if a number is a narcissus number
*/
void Isflower (int Num) {
int Bai = num/100;
int Shi = num/10% 10;
int GE = num% 10;
If hundred * hundred * ten * ten * ten + A * each is equal to this number
If (bai*bai*bai + Shi*shi*shi + Ge*ge*ge = = Num) {
Is the number of daffodils
printf ("%d is the number of daffodils \ n", num);
}else{
otherwise, It's not Narcissus number.
printf ("%d is not narcissus number \ n", num);
}
}
2. Write a function that specifies the sum of all integers between a number and a number
Such as: 3 to 8, calculate the 3+4+5+6+7+8 =?
void Getn2msum (int n,int m) {
int sum = 0;
If (n < M) {//n smaller than M case
For (int i=n; i<=m; I++) {
Sum + = i;
}
}else{//m is smaller than n
For (int i=m; i<=n; I++) {
Sum + = i;
}
}
printf ("%d to%d and%d\n", n,m,sum);
}
3, Use the function to determine whether a year is a leap years
void Isrunyear (int Year) {
If (year% 400 ==0 | | (year%4==0 && Year%100!=0)) {
printf ("%d years is a leap year \ n";
}else{
printf ("%d is common year \ n", year);
}
}
int main (int argc, const char * Argv[]) {
Call syntax: function name (argument list);
Isflower (200);
Getn2msum (100,1);//10+11+12....+20
Isrunyear (1900);
Return 0;
}
The formal and practical parameters of C language