生无涯

吾生也有涯,而知也无涯,以无涯随有涯,乐以忘忧,生亦无涯矣www.cnblogs.com/shengwuya
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2010年10月16日

摘要: /***Straight Insertion Sort**/#define keyType int#include<stdio.h>int insertSort(keyType array[],int n){keyType tmp;for(int i = 1;i < n;i++){tmp = array[i];int j = i -1;while(j >= 0 &&... 阅读全文

posted @ 2010-10-16 23:43 生无涯 阅读(152) 评论(0) 推荐(0) 编辑

2010年10月15日

摘要: /***折半查找:适用于关键字有序的顺序表的查找**/#include<stdio.h>int binarySearch(int a[],int n, int key){int low = 0,high = n - 1;while(low <= high){int mid = (low + high)/2;if(a[mid] == key)return mid;if(a[mid]... 阅读全文

posted @ 2010-10-15 23:57 生无涯 阅读(162) 评论(0) 推荐(0) 编辑

2010年10月14日

摘要: /***perfect number, if a number equals the sum of it's factor,then it is a perfect number.**/#include<stdio.h>int factorSum(int n){int sum = 0;for(int i = 1;i < n;i++){if(0 == n % i)sum += i;... 阅读全文

posted @ 2010-10-14 23:06 生无涯 阅读(242) 评论(0) 推荐(0) 编辑

2010年10月13日

摘要: /***求PI,用正多边形逼近法、数值概率算法**/#include<stdio.h>#include<math.h>double getPI(int n);int main(){int n = 1;double PI;printf("please input the accuracy:\n");scanf("%d",&n);PI = getPI(n);printf... 阅读全文

posted @ 2010-10-13 23:35 生无涯 阅读(180) 评论(0) 推荐(0) 编辑

2010年10月12日

摘要: /***求幂--递归法和非递归法**/#include<stdio.h>#include<math.h>//n>=0,非递归算法乘法次数为O(n)//返回主可能很大,故用unsigned longunsigned long myPower(int m,int n){int p = 1;while(--n >= 0)p = p * m;return p;}//n ... 阅读全文

posted @ 2010-10-12 21:00 生无涯 阅读(162) 评论(0) 推荐(0) 编辑

摘要: 面向对象设计的一些原则“开—闭”原则面向对象设计的基石是“开—闭”原则。“开一闭”原则讲的是:一个软件实体应当对扩展开放,对修改关闭。这个规则说的是,在设计一个模块的时候,应当使这个模块可以在不被修改的前提下被扩展。从另外一个角度讲,就是所谓的“对可变性封装原则”。“... 阅读全文

posted @ 2010-10-12 20:48 生无涯 阅读(323) 评论(0) 推荐(1) 编辑

2010年10月11日

摘要: /***计算组合数C(m,n)(m为下标,n为上标)**/#include<stdio.h>//use the formula: c(m,n) = c(m-1,n) +c(m-1,n-1)int cnr(int m,int n){if(m == n||0 ==n)return 1;elsereturn cnr(m-1,n)+(m-1,n-1);}int main(){int m,n;p... 阅读全文

posted @ 2010-10-11 23:39 生无涯 阅读(145) 评论(0) 推荐(0) 编辑

2010年10月10日

摘要: /**输入五个字符串,按字母顺序排列输出**/#include<stdio.h>#include<string.h>int main(){printf("please input five strings:\n");char tmp[20];char cs[5][20]; //to store the stringsfor(int i = 0;i < 5;i++){g... 阅读全文

posted @ 2010-10-10 23:44 生无涯 阅读(104) 评论(0) 推荐(0) 编辑

2010年10月9日

摘要: /**判断回文数**/#include<stdio.h>int isCircle(int n);int reverse(int m);int main(){int n;printf("please input a number: \n");scanf("%d",&n);if(isCircle(n)){printf("%d is a palindrome\n",n);}else{... 阅读全文

posted @ 2010-10-09 23:53 生无涯 阅读(172) 评论(1) 推荐(0) 编辑

2010年10月8日

摘要: /**计算一个字节中1和0的位数**/#include<stdio.h>int bitNumber(unsigned char c,int & count1,int & count0){unsigned char tmp = 0x1;for(int i = 0;i < 8;i++){if((c & tmp) != 0) {count1 ++;}else c... 阅读全文

posted @ 2010-10-08 21:23 生无涯 阅读(175) 评论(1) 推荐(0) 编辑