When writing a program, sometimes a relatively independent program segment will be used multiple times to achieve the desired function. In this case, we can take this program segment out separately and use it as a separate function.
For example, we want to print the image
Looking at the graph, we can see that the program that appears in the stars will certainly appear twice. We can take this program out separately and use it as a separate function call.
Source program:
# Include <stdio. h>
Star () // The function header can be defined at will, but you 'd better know what functions you want to implement at first glance.
{
Int I, j;
For (I = 1; I <= 4; I ++)
{// What is the execution process of the program with multiple functions? This type of program is always executed from the main function.
When the for (j = 1; j <= I; j ++) number is used, it is executed in the called function body.
Printf ("*");
Puts ("");
}
Return; // when the return statement is executed in the called function, it is returned to the main function for further execution.
}
Main ()
{
Puts ("The first one :");
Star ();
Puts ("The second one :");
Star ();
}
The result is the figure above!