One, c statements
Can be divided into the following five categories:
① expression Statements
An expression;
②, Function call statement
function name (actual parameter table);
③, control statements
Conditional Judgment statement: If statement, switch statement;
Loop execution statement: Do While statement, while statement, for statement;
Turn statement: Break statement, Goto statement, continue statement, return statement.
④, compound statements
A statement consisting of multiple statements enclosed in parentheses {} is called a compound statement.
⑤, empty statements
Only semicolons ";" The composed statement is called an empty statement. Empty statements are statements that do nothing. In the program Hollow statement can be used as an empty loop body
such as:while (GetChar()! ='\ n');
Function: Re-enter as long as the character entered from the keyboard is not a carriage return. The loop body here is an empty statement.
Ii. input/Output functions
scanf ("Format control string", Address table column);
The address is made up of the address operator "&" followed by the variable name.
For example: &a, &b represents the address of variable A and variable B, respectively.
printf ("Format control string", output table column);
"%d" means output by decimal integer;
"%ld" indicates the output by decimal length integer;
"%c" means output by character type and so on.
Putchar function (character output function);
Its function is to output a single character on the display. The general form is:
Putchar (character variable);
GetChar function (keyboard input function);
The function of the GetChar function is to enter a character from the keyboard. The general form is:
GetChar ();
The input character is usually given a character variable, which forms an assignment statement
Practice: To find the root of the ax2+bx+c=0 equation, a, B, C by the keyboard input, set b2-4ac>0.
- #include <stdio.h>
- #include <math.h>
- int main(void){
- float a, b, C, disc, X1, X2, P, Q;
- scanf("a=%f,b=%f,c=%f", &a, &b, &c);
- Disc=b*b-4*a*c;
- P=-b/(2*a);
- Q=sqrt(disc)/(2*a);
- X1=p+q; X2=p-Q;
- printf("x1=%.2f x2=%.2f\ n", x1, X2);
- return 0;
- }
"C-Sequence program structure"