"C-Sequence program structure"

Source: Internet
Author: User

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.

    1. #include <stdio.h>
    2. #include <math.h>
    3. int main(void){
    4. float a, b, C, disc, X1, X2, P, Q;
    5. scanf("a=%f,b=%f,c=%f", &a, &b, &c);
    6. Disc=b*b-4*a*c;
    7. P=-b/(2*a);
    8. Q=sqrt(disc)/(2*a);
    9. X1=p+q; X2=p-Q;
    10. printf("x1=%.2f x2=%.2f\ n", x1, X2);
    11. return 0;
    12. }

"C-Sequence program structure"

Related Article

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.