C programming language statements

1. The basic format of
    the include <stdio.h>
    int main () {
    return 0;
    }
2. Data type
    int, float, double, char
    Example: A char = 'A';
          A + A = 32; or a + = 32; // a = 'a'; legitimate statement. 
3. Output statement
    printf ( "Helloworld \ n") ; // \ t spaces, \ n is newline.
       Output with the output statement int, float, double, char data type.
    printf ( "a =% d, b =% f, e =% c"); //% d is an integer type,% f as a decimal type (float, double),% c as char type ( 'a', ' B ').
    Output String:
`` `
#include <stdio.h>
int main () {
    char STR [] =" http://c.biancheng.net ";
    the printf ("% S \ n-", STR); // output by name as a string    
    printf ( "% s \ n" , "http: //c.biancheng.

    puts ( "http://c.biancheng.net"); // direct output    
    return 0;
} // the puts () and gets () method designed to handle strings.
`` `

4. scanf input statement int, float, double, char data type.
    int A, B;
      Scanf ( "% D,% D", & A, & B);    
    a float type
       a float A, B;
       Scanf ( "% F,% F", & A, & B);
    Double type
        Double A, B;
        Scanf ( "% LF,% LF", & A, & B);
    char type
        char A, B;
        Scanf ( "% C,% C", & A, & B);
5.putchar () statements, getchar () statement
    Example: char a, B, C;
     a = getchar ();
    the putchar (a);
    the putchar ( '\ n-');
6. the definition of the constants
    const int a = 100; // if a on the left side of the assignment operator, will be given .
7. definition array
    int a [100]; // define a 100-element array of type int
    Note: If the array definition, and specifies the initialization of the array length and which do not being initialized array elements, the system automatically defined as 0, (defined as the character '\ 0', defined point type is NULL, i.e., null pointer). Note: When the size of the array of arrays can not be defined as a variable.
    EXAMPLE error: n-int;
    Scanf ( "% D", & n-);
    int A [n-];
8. The defined character string
    char = C 'C';
    char STR [] = "Happy the I AM"; // etc. It is equivalent to: char str1 [] = { ' I', '', 'a', ',' 'm', '', 'h', 'a', 'p', 'p', 'y', '\ 0'}; ( '\ 0' to the end of the flag)
    new string for the old string (for the new shorter than the old, if the new Bi-old long without a problem) ** "C programming" P158.
    A = char "Happy the I AM";
    A = { 'C', 'H', 'A', 'R & lt', '\ 0'} // '\ 0' is at the end, after all no longer showed (not output)


    

1. Select statement example switch-case # include <stdio.h>

main int ()
{
    int type;
    
    Scanf ( "% D", & type);
    / * IF (type ==. 1) 
        the printf ( "Hello");
    the else IF (type == 2) 
        the printf ( "Good morning") ;
    the else IF (of the type == 3)
        printf ( "good evening");
    the else IF (of the type == 4)
        printf ( "goodbye");
    the else
        printf ( "ah, ah?"); 
    
    return 0; * / 
    / / -------------------------------------------
    Switch (type) {/ / type must be of type int 
        Case 1:
            printf ( "Hello");
            BREAK;
        Case 2:
            printf ( "good morning");
            BREAK;
        case 3:
            printf ( "Good evening");
            BREAK;
        Case 4:
            printf ( "Goodbye");
            BREAK;
        default:
            printf ( "? ah, ah");
            
    }
    return 0;
        
} 2. prime - control loop #include < stdio.h>
int main () {
    int x;
    Scanf ( "% D", & x);
    int I;
    int = the isPrime. 1;
    for (I = 2; I <x; I ++) {// x where the maximum occurring as 'x-1', is not X 
        IF (% I X == 0) {
            the isPrime = 0;
                        BREAK;
        }
    }
    IF (the isPrime ==. 1) {
        the printf ( "is a prime number \ n-");
    } the else {
        printf ( "Is not prime \ n-");
    }
        
    return 0;
}

 

Published 34 original articles · won praise 6 · views 4773

Guess you like

Origin blog.csdn.net/qq_42712280/article/details/100858079
Recommended