C和指针 第五章 习题】的更多相关文章

下列输出的值: #include <stdio.h> int func(){ static int count = 1; return ++count; } int main() { int answer = 0; answer = func() - func() * func(); printf("%d\n", answer); return 0; } answer = 2 - 3 * 4; 所以结果 -10: 5.3 编写函数 unsigned int reverse_…
这是第五章 习题5.6的结合版,其中实现了摄像头抓拍功能,能够成功运行. #include "stdafx.h" #include "cv.h" #include "highgui.h" void* getImage() { CvCapture* capture=cvCreateCameraCapture(0); IplImage *img1=NULL,*img2=NULL,*img3=NULL,*frame=NULL,*ppImage=NULL…
第五章习题 1. 我们主要用到下面三个公式: 根据上述公式,我们将式子化简为 对求导即可得到得到公式5-6. 2. (a) 1 - 1/n (b) 自助法是有有放回的,所以第二个的概率还是1 - 1/n (c) 由于自助法是有放回的,且每次抽样都是独立事件,所以概率是(1 - 1/n)^n (d) 答案是1-(1-1/5)^5 = 67.2% (e) 63.4% (f) 63.2% (g) pr = function(n) return(1 - (1 - 1/n)^n) x = 1:1e+05…
6.1编写一个函数,它在一个字符串中进行搜索,查找所有在一个给定字符集中出现的字符,返回第一个找到的字符位置指针,未找到返回NULL #include <stdio.h> char * find_char(char const *source, char const *chars) { char const *sptr = source; char const *cptr = chars; if (sptr == NULL || cptr == NULL) { return NULL; } w…
15.8 十六进制倾印码 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char **argv) { //输入流 FILE *source; //左侧行号区域 int line = 0; //读入的个数 size_t readCount; //循环计数 int idx; //一个字节的16进制字符串 char h…
17.8 为数组形式的树编写模块,用于从树中删除一个值,如果没有找到,程序节点 ArrayBinaryTree.c // // Created by mao on 16-9-18. // #include "ArrayBinaryTree.h" #include <assert.h> #include <stdio.h> unsigned long leftChild(unsigned long current) { return 2 * current; }…
1,1标准输入读入字符,统计各类字符所占百分比 #include <stdio.h> #include <ctype.h> //不可打印字符 int isunprint(int ch){ return !isprint(ch); } //转换表,储存各个判断函数指针 int (*tables[])(int) = {iscntrl, isspace, isdigit, islower, isupper, ispunct, isunprint}; int main() { int co…
1编写calloc,内部使用malloc函数获取内存 #include <stdio.h> #include <stdlib.h> void *myAlloc(unsigned long int length, unsigned long int typeSize) { int *ptr; int index = 0; int totalLen = length * typeSize; if(length >= 0 && typeSize >= 0){…
7.1 hermite递归函数 int hermite(int n, int x) { if (n <= 0) { return 1; } if (n == 1) { return 2 * x; } return 2 * x * hermite(n - 1, x) - 2 * (n - 1) * hermite(n - 2, x); } 7.2两个整型值M和N(m.n均大于0)的最大公约数计算公式: gcd(M,N) 当M % N = 0;  N 当M % N =R, R > 0; gcd(N…
5.4的习题:编写一组函数,实现维数组,函数原型如下: //指定位设置为1void set_bit(char bit_array[], unsigned bit_number); //指定位清零 void clear_bit(char bit_array[], unsigned bit_number); //指定位清零,否则设置为1void assign_bit(char bit_array[], unsigned bit_number, int value); //参数指定位置为1返回真,为0…