Post

note_8_17

c语言知识串讲练习8_17

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <stdio.h>
using namespace std;

int language_points_out_even_num()
{
    /*偶数序列*/
    for(int i=0; i<10;i++)
    {
        if((i)%2==0)
 //记住这里 if i == 0, (i+1)不能写成i, 因为 0%5 ===> 0
        {
            printf("%d ",i);
        }
    }

}
int language_points_out_5_elements()
{

    /*每行输出5个的写法*/
    for(int i=0; i<100;i++)
    {
        printf("%d ",i);
        if((i+1)%5==0)
 //记住这里 if i == 0, (i+1)不能写成i, 因为 0%5 ===> 0
        {
            printf("\n");
        }
    }


    return 0;
}


int test_p104_27()
{
    int x;
    cin >> x ;
    if(x++ >8)
    {
        printf("%d\n",++x);
    }
    else
    {
        printf("---- %d\n",x--);
    }
    return 0;
    
    
}
int test_p101_10()
{
    int a=4,b=5,c=0,i=1,d;
    d=!a&&!b||!c;
    //这里先&& 后 ||
    cout << "d: " << d << endl;
    cout << "a: " << !a << endl;
    cout << "a==1:" << (a==1) << endl;
    //cout << "a=a++=5" << a=a++=5 <<endl;
    //cout << "a=int(i)" << a=int(i);
    return 0;
}

int test_p100_4()
{
//括号、成员运算符 > 单目运算符 > 算数运算符 > 关系运算符 > 逻辑运算符 > 赋值运算符 > 条件运算符 > 逗号
    int a = 3,b=2;

    cout << ((--a!=b++)?--a:++b) <<endl; 
    return 0;
}

int test_p98()
{
    //"/101": 代表八进制下ASCII码中对应的字符
    printf("八进制下的102: \101\n");  
    printf("%d\n",(10!=9));
    printf("十六进制下的41: \x41\n");
    
    return 0;
}
int test_p97()
{
       int i = 10;
    switch(i)
    {
        case 9: i+=1;
        case 10: i+=1;
        case 11: i+=1;
        default: i+=1;
    }
    printf("i: %d\n",i);
    return 0;
 
}
int main()
{
    //test_p100_4();
    // test_p101_10();
    //  test_p104_27();
    language_points_p134_5();
    return 0;
}
This post is licensed under CC BY 4.0 by the author.