随笔分类 -  编程练习小程序

摘要:an / 2 – 1 = an+1 阅读全文
posted @ 2010-05-26 08:17 红脸书生 阅读(521) 评论(0) 推荐(0)
摘要:一个3位数若等于各位的立方和,即是水仙花数 源码如下: 阅读全文
posted @ 2010-05-25 10:22 红脸书生 阅读(331) 评论(0) 推荐(0)
摘要:若x mod 2 =1, x mod 3 = 2, x mod 5 = 4, x mod 6 = 5, x mod 7 =0;求最小解 源码如下: 阅读全文
posted @ 2010-05-25 10:18 红脸书生 阅读(792) 评论(0) 推荐(0)
摘要:一、题目 新郎A,B,C。新娘X,Y,Z。 A说他将和X结婚,X说她将和C结婚,C说他将和Z结婚。这三句全是假的。请问真正是怎么配对‘ 二、分析 可以用穷举法,一共3+2+1种可能方案。 A,B,C位置不变,不断调换X,Y,Z的位置。 三、源码 阅读全文
posted @ 2010-05-25 10:11 红脸书生 阅读(973) 评论(0) 推荐(0)
摘要:1: #include <stdio.h> 2: 3: int Reverse(int i) 4: { 5: int r = 0; 6: while (i) 7: { 8: r = r * 10 + i % 10; 9: i = i / 10; 10: } 11: return r; 12: } 13: 14: int fun(int i, int j) 15: { 16:... 阅读全文
posted @ 2010-05-25 09:56 红脸书生 阅读(507) 评论(0) 推荐(0)
摘要:1: #include <string.h> 2: #include <stdio.h> 3: 4: int IsCircle(int n); 5: int Reverse(int i); 6: 7: int main() 8: { 9: int n; 10: printf("input a number\n"); 11: scanf("%d", &n); 1... 阅读全文
posted @ 2010-05-25 09:42 红脸书生 阅读(377) 评论(0) 推荐(0)
摘要:1: #include <string.h> 2: #include <stdio.h> 3: 4: int Accord(int i, int j, int k); 5: 6: int main() 7: { 8: int i, j, k; 9: for (i=0; i<=100; i++) 10: for (j=0; j<=100; j++) 11: f... 阅读全文
posted @ 2010-05-25 09:36 红脸书生 阅读(291) 评论(0) 推荐(0)
摘要:1: #include <stdio.h> 2: 3: int main() 4: { 5: int red, yellow, green; 6: for (red=0; red<=3; ++red) 7: for (yellow=0; yellow<=3; ++yellow) 8: for (green=2; green<=6; ++green) 9: if(red... 阅读全文
posted @ 2010-05-25 09:32 红脸书生 阅读(619) 评论(0) 推荐(0)
摘要:一、分析 可在较小范围内使用枚举法,验证每一个偶数是否能表示成为两个素数的和。 二、源码 阅读全文
posted @ 2010-05-25 09:27 红脸书生 阅读(460) 评论(0) 推荐(0)
摘要:1: #include <stdio.h> 2: 3: int Gcd(int a, int b) 4: { 5: int min; 6: if (a <= 0 || b <= 0) 7: return -1; 8: if (a > b) 9: min = b; 10: else 11: min = a; 12: 13: while (min) 14: { ... 阅读全文
posted @ 2010-05-25 09:11 红脸书生 阅读(599) 评论(0) 推荐(0)
摘要:1: #include <stdio.h> 2: #include <math.h> 3: 4: int main() 5: { 6: double sum = 0; 7: int i; 8: for (i = 1; i <= 64; ++i) 9: { 10: sum += pow(2, i-1); 11: } 12: printf("the sum is \... 阅读全文
posted @ 2010-05-25 09:05 红脸书生 阅读(539) 评论(0) 推荐(0)
摘要:一、分析 (1)首先分析是否为闰年,若为闰年则2月为29天 (2)其次计算之前的几个月一共有多少天 (3)最终加上该天在月中是多少天 二、源码 阅读全文
posted @ 2010-05-25 08:59 红脸书生 阅读(3129) 评论(0) 推荐(0)
摘要:源码: 阅读全文
posted @ 2010-05-25 08:52 红脸书生 阅读(411) 评论(0) 推荐(0)
摘要:典型的递归求解程序 阅读全文
posted @ 2010-05-25 08:47 红脸书生 阅读(1418) 评论(0) 推荐(0)
摘要:一、问题分析 在所在行中最大,在所在列中最小。所以一个矩阵最多只有一个鞍点。 所以可以逐行寻找鞍点。先找出某行中最大的元素,再将该元素与同列中其他元素进行比较,若该元素同时是所在列中最小的元素,则它就是鞍点。 二、源码 阅读全文
posted @ 2010-05-25 08:37 红脸书生 阅读(4553) 评论(0) 推荐(0)
摘要:1: #include "stdio.h" 2: 3: int main() 4: { 5: float m = 1.0; 6: float n = 1.0; 7: float s = 0.0; 8: int i, j; 9: 10: for (i=1; i<=5; ++i) 11: { 12: for (j=0; j<i; ++j) 13: { 14: m = m * 0.5... 阅读全文
posted @ 2010-05-24 10:53 红脸书生 阅读(447) 评论(0) 推荐(1)
摘要:1: #include "stdio.h" 2: 3: int main() 4: { 5: int i, j, k, buf[7], tmp[7]; 6: 7: for (i=0; i<=6; ++i) 8: { 9: if (i == 0) 10: printf("%d", 1); 11: else if(i == 1) 12: { 13: printf("\n%d %d\n"... 阅读全文
posted @ 2010-05-24 10:44 红脸书生 阅读(507) 评论(0) 推荐(1)
摘要:一、分析 对于特定格式输出的问题,最关键的是理解输出格式的规律。 找出第i行打印的个数与i的关系 找出第i行打印的起始位置与i的关系 二、源码 阅读全文
posted @ 2010-05-24 10:30 红脸书生 阅读(459) 评论(0) 推荐(1)
摘要:一、分析 除2取余法,先得到的是低位,后得到的是高位。所以可以用栈思想计算 二、源码 阅读全文
posted @ 2010-05-24 10:09 红脸书生 阅读(647) 评论(0) 推荐(1)
摘要:一、分析 主要使用<time.h>中的类型和几个函数即可。 clock_t定义了表示时间值的算术类型,一般用于记录存储一个系统时间值。 clock()可以取得从程序运行开始到调用clock()函数所花费的处理器时间,返回类型就是clock_t。 (end - start) / CLK_TCK就可以将时间差转换为以秒为单位 二、源码 阅读全文
posted @ 2010-05-24 10:02 红脸书生 阅读(431) 评论(0) 推荐(1)