
Points on C reading
文章平均质量分 65
waterathena
be a fashional lady
write clean code
展开
-
不定长参数序列使用方法
这个例子用来求几个数的平均 数:/**//*** Compute the average of the specified number of values.*/#include stdarg.h>float average( int n_values, ... )...{ va_list var_arg; int count; float sum = 0; /**//* ** Prepa原创 2007-10-09 18:23:00 · 757 阅读 · 0 评论 -
矩阵相乘
/*** Multiply two matrices together.*/void matrix_multiply( int *m1, int *m2, register int *r, int x, int y, int z ){ register int *m1p; register int *m2p; register int k; int row; int column;原创 2007-10-18 10:21:00 · 588 阅读 · 0 评论 -
计算一个数的开平方后值
不知道是不是自己大学时代本科的数值分析学的有点忘记了,不太记得计算开平方的算法了。在Points ON C 上看到这个算法,倍感亲切。/*** Compute the square root of a number.*/#include #include intmain(){ float new_guess; float last_guess; float number; /原创 2007-10-18 10:17:00 · 1318 阅读 · 0 评论 -
字符的大小写转换
其实在C语言库里面这些已经实现了,我们直接调用相应的函数就可以了。但是有时候面试题里面好像会有些这样的考题。本科的面试题,想想自己当初的那个情景就知道了。个中滋味,频上心头。大写转小写:int ch; while( (ch = getchar()) != EOF ){ if( ch >= A && ch ch += a - A; putchar( ch );翻译 2007-10-18 10:14:00 · 776 阅读 · 0 评论 -
简单的括号配对判断
虽然这里只使用了括号的计数,实现加减法则来配对括号。思想可以扩展:利用栈来实现括号的配对是十分简单的。/*** Check the pairing of braces in a C program.*/#include #include intmain(){ int ch; int braces; braces = 0; /* ** Read the program ch翻译 2007-10-18 10:11:00 · 799 阅读 · 1 评论 -
字符串转成整数
int ascii_to_integer( char *string ){ int value; int digit; value = 0; /* ** Convert digits of the string one by one. */ while( *string >= 0 && *string value *= 10; value += *string - 0;翻译 2007-10-18 10:03:00 · 676 阅读 · 0 评论 -
堆栈实现
/**//*** Interface for a stack module*/#define STACK_TYPE int /* Type of value on the stack *//**//*** push** Pushes a new value on the stack. The argument is the value** to be pushed.*/void push(翻译 2007-10-18 09:59:00 · 612 阅读 · 0 评论 -
函数指针使用
在这里例子是一个单链表节点的查找的例子:node.h文件/**//*** Sample declaration for a linked list node. Change this declaration** as appropriate for your list values and recompile the linked list** search function wit原创 2007-10-18 09:52:00 · 906 阅读 · 0 评论 -
有序单链表节点的插入
sll_node.h文件typedef struct NODE ...{ struct NODE *link; int value;} Node; insert.c文件 /**//*** Insert into an ordered, singly linked list. The arguments are a pointer to the root p原创 2007-10-18 09:47:00 · 1296 阅读 · 0 评论 -
字符串拷贝
如果发现有更好的写法,Carpicorn会更新的。:-)/*** Copy the string contained in the second argument to the** buffer specified by the first argument. 用第一个字符串的空间之间保存拷贝过来的字符串*/#include void strcpy( char *buffer, cha原创 2007-10-18 09:44:00 · 641 阅读 · 0 评论 -
菲波拉契数列(递归与迭代)
/*** Compute the value of the nth Fibonacci number, recursively. 递归法*/long fibonacci( int n ){ if( n return 1; return fibonacci( n - 1 ) + fibonacci( n - 2 );} /*** Compute the value of翻译 2007-10-18 09:39:00 · 832 阅读 · 0 评论 -
计算阶乘(递归与迭代)
学了三个单词:factorial 阶乘,recursivly 递归地、iteratively迭代地/*** Compute the factorial of n, recursively 递归法计算阶乘*/long factorial( int n ){ if( n return 1; else return n * factorial( n - 1 );}/*** Com翻译 2007-10-18 09:36:00 · 2608 阅读 · 0 评论 -
在字符串数组中查找值
(*^__^*) 嘻嘻……/*** Given a pointer to a NULL-terminated list of pointers, search** the strings in the list for a particular character.*/#include #define TRUE 1#define FALSE 0intfind_char(翻译 2007-10-09 17:39:00 · 991 阅读 · 0 评论 -
计算字符串长度
/**//*** Compute the length of a string.*/#include stdlib.h>#include assert.h>size_tstrlen( char *string )...{ assert(string != null); int length = 0; /**//* ** Advance through the string, counting翻译 2007-10-09 17:36:00 · 611 阅读 · 0 评论 -
纪念大学第一个编程语言 C language
熟悉C language 的人都知道 Points C是一本经典的C语言著作。平时为了训练编程思想,各种书和代码都看。虽然现在使用C的时候很少,但是C语言曾经是大学开设的第一门编程语言课题。接触了C后又接触了Java 、 C++、 Assebly、C#等。************Hust C 语言宝典*************还记得当时Hust的C语言课程正好改革,我们只上了半学期就考原创 2007-10-09 17:24:00 · 894 阅读 · 0 评论 -
计算一个数的二进制表示中有多少个1
这个阶段的我好像很喜欢把玩code。拿到Code会想它是否能够工作。先使用,再Trace,然后总结归纳。这些都是从Points C中摘录的。不知道文章该该怎么分类。所以暂且归为翻译这一栏目。现在看来还是觉得这些简短的Code很经典。 *********************************************方法一************************翻译 2007-10-09 17:34:00 · 869 阅读 · 0 评论 -
反转整数bit位
/*** Reverse the order of the bits in an unsigned integer value.*/unsigned intreverse_bits( unsigned int value ){ unsigned int answer; unsigned int i; answer = 0; /* ** Keep going as long as翻译 2007-10-18 10:27:00 · 1302 阅读 · 0 评论