程序片段(01):函数.c+call.c+测试.cpp
内容概要:函数
#include <stdio.h>
#include <stdlib.h>
int main01(void)
{
system("tasklist");
system("pause");
}
int getres(int a, int b, int c);
int main01(void)
{
int x = 11, y = 12, z = 13;
x = x*x*x;
y = y*y*y;
z = z*z*z;
int res = x + y + z;
res = getres(x, y, z);
printf("%d \n", res);
int a = 10, b = 12, c = 13;
a = a*a*a;
b = b*b*b;
c = c*c*c;
int res1 = a + b + c;
res1 = getres(a, b, c);
printf("res1 = %d \n", res1);
system("pause");
}
int getres(int a, int b, int c)
{
return a*a*a + b*b*b + c*c*c;
}
- 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
- 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
int main02(void)
{
system("calc");
system("pause");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b);
int main03(void)
{
add(1, 2);
printf("%d \n", add(10, 20));
system("pause");
}
int add(int a, int b)
{
return a + b;
}
- 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
- 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
程序片段(02):C语言函数调用实例.c+函数.c+run.c
内容概要:函数的分割+函数的划分
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main01(void)
{
int a;
int b;
scanf("%d,%d", &a, &b);
if (b == 0)
{
abort();
}
printf("%d \n", a / b);
system("pause");
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void run(char *path)
{
ShellExecuteA(0, "open", path, 0, 0, 1);
}
int main02(void)
{
system("pause");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
#include <stdio.h>
#include <stdlib.h>
int getmax(int a, int b);
int getmax(int a, int b)
{
return a > b ? a : b;
}
int main03(void)
{
printf("%p \n", getmax);
system("pause");
}
- 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
- 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
程序片段(03):void.c+fun.c
内容概要:函数的使用和参数
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b);
int main01(void)
{
printf("%d \n", add(10, 20));
return 1;
system("pause");
}
add(int a, int b)
{
return a + b;
}
int main02(void)
{
getchar();
getchar();
system("pause");
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
void change(int a)
{
a = 3;
printf("&change = %p, change = %d \n", &a, a);
}
int main03(void)
{
change(10);
system("pause");
}
int main04(void)
{
int a = 10;
printf("&main = %p, main = %d \n", &a ,a);
change(a);
printf("%d \n", a);
system("pause");
}
- 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
- 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
程序片段(04):输入输出.c+return.c
内容概要:return与参数
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b)
{
printf("add1 a = %d, b = %d \n", a, b);
a = 19;
b = 29;
printf("add2 a = %d, b = %d \n", a, b);
return a + b;
}
int main01(void)
{
int a = 10;
int b = 20;
printf("%d \n", add(a, b));
printf("%d \n", add(11, 12));
printf("main a = %d, b = %d \n", a, b);
system("pause");
}
int add_debug(int a, int b)
{
printf("a = %p, b = %p \n", &a, &b);
printf("a = %d, b = %d \n", a, b);
a = 1;
b = 2;
int x = 3;
int y = 4;
printf("x = %p, y = %p \n", &x, &y);
printf("x = %d, y = %d \n", x, y);
printf("\n");
}
int main02(void)
{
printf("error = %d \n",add_debug(1, 2, 3, 4, 5) );
system("pause");
}
int add_test(int a, int b)
{
return a + b;
}
int main03(void)
{
printf("%d", add_test(11.9, 2, 3, 5, 10, 12));
system("pause");
}
int add_test1(int a, int b)
{
return 13.9;
}
int main04(void)
{
printf("%d \n", add_test1(1, 2));
system("pause");
}
- 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
- 107
- 108
- 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
- 107
- 108
#include <stdio.h>
#include <stdlib.h>
int addx()
{
return 1;
}
int main05(void)
{
printf("%d \n", addx());
system("pause");
}
int getnum()
{
int num;
printf("%p \n", &num);
num = 10;
return 10.9;
system("notepad");
}
void show()
{
system("notepad");
return;
}
void showx()
{
for (int i = 1; i < 100; i++)
{
if (i % 13 == 0)
{
printf("%d ", i);
return;
}
}
}
int main06(void)
{
printf("%d \n", getnum());
showx();
system("pause");
}
int main07(void)
{
system("pause");
}
int add(int a, int b)
{
return a + b;
}
int main08(void)
{
printf("%d \n", add(add(add(1, 2), 3), 4));
system("pause");
}
- 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
- 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
内容概要(05):过程.c
内容概要:函数执行过程
#include <stdio.h>
#include <stdlib.h>
int main01(void)
{
printf("main 上 \n");
void print1();
print1();
printf("%d \n", add(-1, 0));
printf("main 下 \n");
system("pause");
}
int add(int a, int b)
{
return a + b;
}
void print1()
{
printf("print1 上 \n");
printf("print1 下 \n");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
程序片段(06):Go.c
内容概要:函数参数的运算顺序
#include <stdio.h>
#include <stdlib.h>
void show(int a, int b)
{
printf("a = %d, b = %d \n", a, b);
}
int main01(void)
{
int a = 5;
show(a, a++);
system("pause");
}
int add(int a, int b)
{
printf("&a = %d, &b = %d \n", &a, &b);
printf("a = %d, b = %d \n", a, b);
int x = 1;
int y = 2;
printf("&x = %d, &y =%d \n", &x, &y);
printf("x = %d, b = %d \n", x, y);
return a + b;
}
int main02(void)
{
printf("%d \n", add(1, 2, 3));
system("pause");
}
- 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
- 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
程序片段(07):main.c
内容概要:CodeBlocks测试
#include <stdio.h>
#include <stdlib.h>
void show(int a, int b)
{
printf("a=%d,b=%d", a, b);
}
int main()
{
int a = 5;
show(a, a++);
getchar();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
程序片段(08):可变参数.c
内容概要:可变参数
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int add(int num, ...)
{
int res = 0;
va_list argp;
va_start(argp, num);
for (int i = 0; i < num; i++)
{
res += va_arg(argp, int);
}
va_end(argp);
return res;
}
int main01(void)
{
printf("%d \n", add(3, 1, 2, 3));
printf("%d \n", add(4, 1, 2, 3, 4));
printf("%d \n", add(5, 1, 2, 3, 4, 5));
system("pause");
}
int main02(void)
{
printf("%d, %d, %d \n", 1, 2, 3);
printf("%d, %s, %c, %d \n", 1, "123", \'A\', 4);
system("pause");
}
void go(int num, ...)
{
va_list argp;
va_start(argp, num);
for (int i = 0; i < num; i++)
{
char str[50];
system(va_arg(argp,char *));
}
va_end(argp);
}
int main03(void)
{
go(3, "notepad", "calc", "tasklist & pause");
system("pause");
}
void showint(int start, ...)
{
va_list argp;
va_start(argp, start);
int argvalue = start;
do
{
printf("\n %d", argvalue);
argvalue = va_arg(argp, int);
} while (argvalue != -1);
va_end(argp);
}
int main04(void)
{
showint(1, 2, 3, 4, 5, -1);
system("pause");
}
- 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
- 107
- 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
- 107
程序片段(09):C声明.c+函数声明.c+int.c+全局与局部冲突
内容概要:C语言函数声明+全局变量与局部变量
#include <stdio.h>
#include <stdlib.h>
int main01(void)
{
printf("Hello China! \n");
printf;
system("pause");
}
int main02(void)
{
add(2, 3);
print();
system("pause");
}
int print(){}
int add(int a, int b)
{
return a + b;
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b);
int add(int x, int y);
int add(int h, int j);
int add(int k, int l);
int main03(void)
{
printf("%d", add(1, 2));
system("pause");
}
int add(int a, int b)
{
return a + b;
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
int a;
int main04(void)
{
printf("%d \n", a);
system("pause");
}
int main05(void)
{
a = 9;
system("pause");
}
void go()
{
a = 11;
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
int a;
int a;
int a = 3;
int main06(void)
{
printf("%d \n", a);
system("pause");
}
int main07(void)
{
int a = 10;
printf("%d \n", a);
{
printf("%d \n", a);
int a = 13;
printf("%d \n", a);
}
printf("%d \n", a);
system("pause");
}
- 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
- 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
程序片段(10):test.cpp
内容概要:声明与定义差别
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b);
int add(int x, int y);
int add(int a, int b)
{
return a + b;
}
int main01(void)
{
add(1, 2);
system("pause");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
程序片段(11):baidu.c+stack.c
内容概要:函数调用流程简单递归
#include <Windows.h>
_declspec(dllexport) void go()
{
Sleep(1);
go();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
#include <stdio.h>
#include <stdlib.h>
void revInt(unsigned int value)
{
unsigned int quotient = value / 10;
if (quotient != 0)
revInt(quotient);
putchar(value % 10 + \'0\');
}
void printInt1(int value)
{
if (value - 1 > 0)
printInt1(value - 1);
putchar(value + \'0\');
}
void printInt2(int value1, int value2)
{
printf("%d \n", value1);
if ((value1 + 1) <= value2)
printInt2(value1 + 1, value2);
}
void printStr(char *str)
{
if (*str)
{
printStr(++str);
putchar(*str);
}
}
unsigned int calFact1(unsigned int value)
{
if (0 == value || 1 == value)
return 1;
calFact1(value - 1);
return value * calFact1(value - 1);
}
unsigned int calFact2(unsigned int value)
{
if (0 == value || 1 == value)
return 1;
else
return value * calFact2(value - 1);
}
void printIntToBin1(unsigned long value)
{
unsigned long quotient = value / 2;
if (0 != quotient)
printIntToBin1(quotient);
putchar((value % 2) + \'0\');
}
void printIntToBin2(unsigned long value)
{
unsigned long remainder = value % 2;
if (value / 2 > 0)
printIntToBin2(value / 2);
putchar(remainder ? \'1\' : \'0\');
}
void loopToRecursion(long value)
{
printf("%d, %p \n", value, &value);
if (value < 9)
loopToRecursion(value + 1);
}
int main01(void)
{
system("pause");
}
int main02(void)
{
printf("12345");
main02();
}
void intPrintStr(char *str, unsigned long value)
{
if (0 == value)
return;
if (value - 1 > 0)
intPrintStr(str, --value);
printf("%s \n", str);
}
void printNontepad(unsigned long value)
{
if (0 == value)
{
return;
}
else
{
system("notepad");
printNontepad(value - 1);
}
}
unsigned long addNum(unsigned long value)
{
if (1 == value)
return 1;
return addNum(value - 1) + value;
}
int main03(void)
{
system("pause");
}
- 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
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 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
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
程序片段(12):线性递归.c+树状递归.c+汉诺塔.c
内容概要:递归
#include <stdio.h>
#include <stdlib.h>
void main01(void)
{
main01();
}
void loopToRecursion(unsigned int value)
{
if (value >= 5)
return;
else
loopToRecursion(value + 1);
system("notepad");
}
unsigned long countInt(unsigned long value)
{
if (value == 1)
return 1;
return value + countInt(value - 1);
}
void uLongToBin(unsigned long value)
{
unsigned long quotient = value / 2;
if (quotient != 0)
uLongToBin(quotient);
putchar(value % 2 ? \'1\' : \'0\');
}
int main02(void)
{
uLongToBin(100);
system("pause");
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
unsigned long countRabbit1(unsigned long month)
{
if (1 == month || 2 == month)
return 1;
return countRabbit1(month - 2) + countRabbit1(month - 1);
}
void countRabbit2(unsigned long month)
{
if (1 == month || 2 == month)
printf("1 \n");
else
{
int f1 = 1;
int f2 = 2;
int f3 = f1 + f2;
for (int i = 3; i < month; i++)
{
f3 = f1 + f2;
f1 = f2;
f2 = f3;
}
printf("f3= %lu \n", f3);
}
}
int main01(void)
{
printf("%lu \n", countRabbit1(40));
countRabbit2(40);
system("pause");
}
- 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
- 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
#include <stdio.h>
#include <stdlib.h>
void hanoiTower(unsigned long num, char x, char y, char z)
{
if (1 == num)
{
printf("%c-->%c \n", x, z);
return;
}
hanoiTower(num - 1, x, z, y);
printf("%c-->%c \n", x, z);
hanoiTower(num - 1, y, x, z);
}
int main04(void)
{
hanoiTower(4, \'A\', \'B\', \'C\');
system("pause");
}