Start to learn C ++ and C

Source: Internet
Author: User

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:" }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.