Start to learn C ++ and C
Today is the first article to record the course of blog activation. Recently, I started to learn C ++ again. The bibliography "C ++ primer PLUS". The editor edits Leetcode online (this editor does not support cin)
2.4.3 User-Defined Functions
# Include <iostream>
# Include <cmath>
Void simon (int); // The statement is a statement that requires extra points!
Int main (){
Using namespace std;
Simon (3 );
Int count;
Cin> count;
Simon (count );
Cout <"Done! "<Endl;
Return 0;
}
Void simon (int n) // function definition is not a statement and no extra points are required. The function header accepts a parameter and returns a value (void type)
{
Using namespace std;
Cout <"Simon says touch you toes" <n <"times" <endl;
} // Function body, combined with the function header as a prototype.
2.4.5 Using namespace std;
Put using namespace std at the beginning, and all subsequent functions can use all the elements of the namespace std.
Exercise:
2 unit conversion
# Include <iostream>
# Include <cmath>
Double LenMa (double LenLong );
Int main (){
Using namespace std;
Double LenLong = 5; // The variable must be declared before use, unlike matlab/python.
Double Lenma = LenMa (LenLong );
Cout <LenLong <"long" <"is" <Lenma <"Ma" <endl;
Return 0;
}
Double LenMa (double LenLong)
{
Return 200 * LenLong;
}
3. Statement output
# Include <iostream>
# Include <cmath>
Using namespace std;
Void Out1 (int n );
Void Out2 (int n );
Int main (){
Using namespace std;
Int n = 2;
Int m = 2;
Out1 (n );
Out2 (m );
Return 0;
}
Void Out1 (int n)
{
For (int I = 1; I <= n; I ++)
Cout <"Three blind mice" <endl;
}
Void Out2 (int n)
{
For (int I = 1; I <= n; I ++)
Cout <"See how they run" <endl;
}
4 unit conversion
# Include <iostream>
# Include <cmath>
Using namespace std;
Double Temptrans (double n );
Int main (){
Cout <"Please enter a Celsius value :";
Double n;
Cin> n;
Cout <n <endl;
Cout <n <"degrees Celsius is" <Temptrans (n) <"degrees Fahrenheit" <endl;
}
Double Temptrans (double n)
{
Return (1.8 * n + 32.0 );
}
7. Numerical output
# Include <iostream>
# Include <cmath>
Using namespace std;
Void Timeout (int n, int m );
Int main (){
Int hour;
Int minute;
Cout <"Enter the number of hours :";
Cin> hour;
Cout Cout <"Enter the number of minutes :";
Cin> minute;
Cout <minute <endl;
Timeout (hour, minute );
Return 0;
}
Void Timeout (int hour, int minute)
{
Cout <"Time:" }