1.主函数已知,编写一个函数实现将整型数组中的偶数删除,然后输出改变后的数组。
1 |
|
1 | #define MAXSIZE 1024 |
#1.宏编程1
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
原代码:
1 | void merge(int a[] ,int n, int b[] , int m , int *c) { |
答案为:
1 | #include "stdio.h" |
1 | //实验10 进阶3/ |
1 | //实验10 进阶6/ |
1 | #include "stdio.h" |
通过指针,可以简化一些C编程任务的执行,还有一些任务,如动态内存的分配,没有指针是无法执行的。
指针是一个变量,其值为另一个变量的地址,即,内存位置的直接地址。就像其他变量或常量一样,使用指针存储其他变量地址之前,需要对其进行声明,
1 | //指针学习 |
在变量声明的时候,如果没有确切的地址可以赋值,为指针变量赋一个 NULL 值是一个良好的编程习惯。赋为 NULL 值的指针被称为空指针。
在大多数的操作系统上,程序不允许访问地址为 0 的内存,因为该内存是操作系统保留的。然而,内存地址 0 有特别重要的意义,它表明该指针不指向一个可访问的内存位置。但按照惯例,如果指针包含空值(零值),则假定它不指向任何东西。
1 | //检查一个空指针 |
我们喜欢在程序中使用指针代替数组,因为变量指针可以递增,而数组不能递增,数组可以看成一个指针常量。下面的程序递增变量指针,以便顺序访问数组中的每一个元素:
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 | #include "stdio.h" |
1 |
1 | #include<stdio.h> |
1 | #include<stdio.h> |
1 | //实验七 基础3 |
在主函数main中输入一个实数 x 和正整数m,调用该函数求这个实数 x 的m次幂。要求该函数能够正确地计算负幂。同时,该函数实现 0 的任何次幂为 0 ,并 且任何数值的 0 次幂为 1 。使用循环方法实现。建议函数原型:double Power(double dblRealNumber , int intPositiveNumber) ;
1 | //实验七 进阶7 |
1 | #字符串相加 |
由于函数传递时实参无法改变,所以使用了全局变量来完成
1 | #include <stdio.h> |
使用数组,从而避免使用了全局变量
1 | #include <stdio.h> |
1 | /*rand函数用来产生随机数,但是rand()的内部是用线性同余法实现的,是伪随机数。在调用rand函数之前,可以使用srand函数设置随机数种子,如果没有设置随机数种子,rand函数在调用时,自动设计随机种子为1.随机种子相同,每次产生的随机数都是相同的,这就是为什么叫做伪随机数。*/ |