C语言实现高随机序列

程序代码: #include <stdio.h>#include <timeb.h>/*返回随机数序列初值*/double Initial(){ double init; struct timeb *tmb; while(1) { ftime(tmb); /*利用DOS系统的时钟产生随机数序列初值*/ init=tmb->millitm*0.9876543*0.001; if(init>=0.001) break; } retur...
默认分类 | 2010-02-22 22:27 | 阅读 1459 次 | 评论 0 条

[C语言]背包问题

程序代码:#include<stdio.h>#define NUM 10/* 定义物品总数*/#define CONTENT 10 /*定义包的容量*/void knapsack(int v[NUM],int w[NUM],int c,int m[NUM ][CONTENT]){ int n=NUM-1; int i,j; int jMax; if((w[n]-1)< c) jMax = w[n]-1; else jMax = c; /* 初始化m[n][j] */ for(j = 0; j <= jMax; j++) m[n]...
默认分类 | 2010-02-22 22:24 | 阅读 1706 次 | 评论 0 条

[C语言]大整数阶乘思路

#include<stdio.h>#include<stdlib.h>/*定义数组的最大位数*/#define MAXARRAY 1000int main(){ int fac[MAXARRAY],add[MAXARRAY]; int top,n,i,j; char ch; clrscr(); while(1) { /*输入要计算的整数*/ while(1) { printf("Please input the integer to compute:\n"); sca...

[C语言]用while语句求n!

程序代码:#include<stdio.h>#include<stdlib.h>int main(){ int i = 0;/* i为计数器 */ int n; int factorial = 1;/* 保存阶乘的结果 */ puts("*************************************"); puts("* The program will compute *"); puts("* the factotial of an integer *"); puts("****************...

[C语言]用for循环模拟自由落体

程序代码:#include<stdio.h>#include<conio.h> #include<time.h> int main() { /*(x,y)表示物体在屏幕上的初始位置, depth表示物体落地后反弹的高度, times用来控制时间的延迟, m用来控制运动的方向,m=-1说明是向下运动,m=1说明是向上运动*/ int x=15,y=4,depth=20,times=20,m=1,i,j; for(;depth!=0;) { m=-m; if(m==1) depth--; ...
默认分类 | 2010-02-22 22:15 | 阅读 2460 次 | 评论 1 条

C语言时钟程序

程序代码:#include <stdio.h> #include <math.h>#include <dos.h>#include <conio.h> void main(){ struct time curtime; float th_hour,th_min,th_sec; do { printf("*********************************************\n"); printf("** This is a simple clock program. **\n");...
默认分类 | 2010-02-22 22:02 | 阅读 1972 次 | 评论 0 条

用C语言编写简单的计算器

C语言代码:#include <stdio.h>char token;/*定义程序要使用到的一些函数*/void match( char expectedToken ) /*对当前的标志进行匹配*/{ if( token == expectedToken ) token = getchar(); /*匹配成功,获取下一个标志*/ else { printf("cannot match\n"); exit(1); /*匹配不成功,退出程序*/ }}int low( void )/*用于计算表达式中级别最低的运算*/{ ...
浏览19275次