I have never learned C language and only learned C ++ before, so I learned C language. In fact, I personally think the difference between C and C ++ is very small, basically, the difference between the output and input of printf and scanf is that the header file to be included is different. For example, in C ++, it is # include <iostream>. In C, it is # include <stdio. h>.
When calling printf and scanf, you must include # include <stdio. h>
Printf is used: printf ("format control string", output parameter 1, output parameter 2 );
The format control string contains: Format control instructions, common characters
The format control description mainly refers to the output of data in the specified format, including the format control characters starting with %. Different types of data use different formats to control characters (INT type uses % d, % F for float and double)
Common characters are the characters that are output as they are, for example, Fahr = % d, Celsius = % d \ n in "Fahr = % d, Celsius = % d \ n ".
Scanf is used: scanf ("format control string", input parameter 1, input parameter 2 );
The format control string contains: Format control instructions, common characters
The format control string represents the input format (% d for int type, % F for float, and % lf for double type)
Common character: the usage of printf is the same as that mentioned above.
The input parameter is the address of the variable, so you must add &
1. printf ("Fahr = % d, Celsius = % d \ n", Fahr, Celsius );
2. printf ("Enter x (x> = 0): \ n ");
3. printf ("Y = f (% F) = %. 2f \ n", x, y );
% F indicates that floating point data is output in decimal form, with 6 decimal places retained, while %. 2f indicates that two decimal places are retained during output.
4. scanf ("% lf", & X); // read the input
Call the input data of the scanf () function. Before the variable name X, add &. % L in LF is the first letter of long, the input parameters of the scanf function must correspond to the format control description in the format control string,
And their types, numbers, and locations must correspond one by one.
Scanf ("% d % lf", & X, & Y, & Z) indicates that the input x is of the int type, and Y is of the int type, Z is of the double type. This is a one-to-one correspondence.