平方根.c
<P>#define Epsilon 1.0E-6/*控制解的精度*/ <BR>#include <stdio.h><BR>#include <math.h> </P><P>main() <BR>{<BR> float num,pre,this; <BR>do <BR> { <BR> scanf("%f",&num);/*输入要求平方根的数*/ <BR> }while(num<0); <BR> if (num==0) <BR> printf("the root is 0"); <BR> else <BR> {<BR>this=1; <BR> do<BR> { <BR> pre=this;<BR> this=(pre+num/pre)/2; <BR>}while(fabs(pre-this)>Epsilon);/*用解的精度,控制循环次数,fabs()是求绝对值的函数*/ <BR> } <BR> printf("the root is %f",this); <BR>} </P>
圆周率.c
#include<stdio.h><BR>long a=10000,b,c=2800,d,e,f[ 2801 ],g; <BR>main()<BR>{<BR> for(;b-c;)<BR>f[ b++ ]=a/5; <BR> for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a) <BR>for(b=c;d+=f[ b ]*a,f[ b ]=d%--g,d/=g--,--b;d*=b);<BR>}灯塔问题.c
//灯塔问题<BR>#include <iostream.h><BR>#include <fstream.h><BR>#include <conio.h><BR>int sz,cf=1,k,n,a,b,c;<BR>void shuru(void);<BR>void shuchu(void);<BR>bool panduan(void);<BR>void goujian(void);<BR>void main()<BR>{<BR> int i,j,lj=0,d;<BR> shuru();<BR>for(i=1;i<=n;i++)cf=cf*2;<BR>for(i=0;i<cf;i++)<BR>{<BR> d=i;<BR> for(j=1;j<=n;j++)<BR> {sz=d%2;d=d/2;}<BR> goujian();<BR> if(panduan()==true){lj=lj+1;shuchu();}<BR>}<BR>cout<<"共有"<<lj<<"种情况"<<endl;<BR>getch();<BR>}<BR>void goujian(void)<BR>{<BR> int i1,j1;<BR> for(i1=n-1;i1>0;i1--)<BR> {<BR>for(j1=1;j1<=i1;j1++)<BR>{<BR> if(sz==1&&sz==1)<BR> sz=0;<BR> if(sz==0&&sz==0)<BR> sz=0;<BR> if(sz==1&&sz==0)<BR> sz=1;<BR> if(sz==0&&sz==1)<BR> sz=1;<BR>}<BR>}<BR>}<BR>bool panduan()<BR>{<BR> int pd=1,j1;<BR>for(j1=1;j1<=k;j1++)<BR> if(sz]]!=c) pd=0;<BR>if(pd==0) return false;else return true;<BR>}<BR>void shuchu(void)<BR>{<BR> int i2,j2;<BR>for(i2=1;i2<=n;i2++)<BR>{<BR> for(j2=1;j2<=n-i2;j2++) cout<<" ";<BR>for(j2=1;j2<=i2;j2++) cout<<sz<<" ";<BR>cout<<endl;<BR> }<BR>cout<<endl;<BR>}<BR>void shuru(void)<BR>{<BR>// char filename;<BR>ifstream input;<BR>// cout<<"Input filename:";<BR>// cin>>filename;<BR>// input.open(filename);<BR>input.open("dt.txt");<BR>input>>n;<BR>k=0;<BR>do{<BR> k++;<BR>input>>a>>b>>c;<BR>}while((a!=0)&&(b!=0));<BR>k--;<BR>}16进制10进制.c
<P>//返回16进制字符串s对应的整数值,遇到任何一个非法字符都返回-1。<BR>int HexToDec(char *s)<BR>{<BR> char *p = s;</P><P> //空串返回0。<BR> if(*p == '\0')<BR>return 0;<BR> <BR> //忽略开头的'0'字符<BR> while(*p == '0')<BR>p++;</P>
<P> int dec = 0;<BR> char c;</P>
<P> //循环直到字符串结束。<BR> while(c = *p++)<BR> {<BR>//dec乘16<BR>dec <<= 4;<BR><BR>//数字字符。<BR>if(c >= '0' && c <= '9')<BR>{<BR> dec += c - '0';<BR> continue;<BR>}</P>
<P>//小写abcdef。<BR>if(c >= 'a' && c <= 'f')<BR>{<BR> dec += c - 'a' + 10;<BR> continue;<BR>}</P>
<P>//大写ABCDEF。<BR>if(c >= 'A' && c <= 'F')<BR>{<BR> dec += c - 'A' + 10;<BR> continue;<BR>}</P>
<P>//没有从任何一个if语句中结束,说明遇到了非法字符。<BR>return -1;<BR> }</P>
<P> //正常结束循环,返回10进制整数值。<BR> return dec;<BR>}<BR></P>
矩阵转换.c
<P>void trans(int *p,int n)<BR>{<BR> int i,j,temp;<BR> int *pi,*pj;<BR> for(i=0;i<=n-1;i++)<BR> {<BR>for(j=0;j<=i;j++)<BR> {<BR> pi =p +i*n;/*p首地址 */<BR> pj =p +j*n;<BR> temp=pi;<BR> pi=pj;<BR> pj=temp;<BR> }</P><P> }<BR> return;<BR>}</P>
<P>main()<BR>{<BR> int a={ 1, 2, 3, 4,<BR> 5, 6, 7, 8,<BR> 9, 10,11,12,<BR> 13,14,15,16};<BR> int i,j;<BR> printf("before transform:\n");<BR> for(i=0;i<=3;i++)<BR> {<BR> for(j=0;j<=3;j++)<BR> printf("%d",a);<BR> printf("\n");<BR> }<BR> trans((int*)a,4);<BR> <BR> printf("after transform:\n");<BR> for(i=0;i<=3;i++)<BR> {<BR> for(j=0;j<=3;j++)<BR> printf("%d",a);<BR> printf("\n");<BR> }<BR> return;<BR>}</P>
杨辉三角形.c
<P>#include <stdio.h><BR>int c(x,y);<BR>main()<BR>{<BR>int i,j,n=13;<BR>printf("N=");<BR>while(n>12)<BR>scanf("%d",&n);<BR>for(i=0;i<=n;i++)<BR>{<BR>for(j=0;j<12-i;j++)<BR>printf(" ");<BR>for(j=1;j<i+2;j++)<BR>printf("%6d",c(i,j));<BR>printf("\n");<BR>}<BR>}</P><P>int c(x,y)<BR>int x,y;<BR>{<BR>int z;<BR>if((y==1)||(y==x+1))return(1);<BR>z=c(x-1,y-1)+c(x-1,y);</P>
<P>return(z);<BR>}</P>
数组操作.c
<P>#include <stdio.h></P><P>void main()<BR>{<BR> char strg,*there,one,two;<BR> int *pt,list,index;</P>
<P> strcpy(strg,"This is a character string.");</P>
<P> one = strg; /* one 和 two是相同的 */<BR> two = *strg;<BR> printf("第一输出的是 %c %c\n",one,two);</P>
<P> one = strg; <BR> two = *(strg+8);<BR> printf("第二输出的是 %c %c\n",one,two);</P>
<P> there = strg+10; /* strg+10 等同于 strg */<BR> printf("第三输出的是 %c\n",strg);<BR> printf("第四输出的是 %c\n",*there);</P>
<P> for (index = 0;index < 100;index++)<BR> list = index + 100;<BR> pt = list + 27;<BR> printf("第五输出的是 %d\n",list);<BR> printf("第六输出的是 %d\n",*pt);<BR>}<BR></P>
桶排序.c
<P>#include<stdio.h></P><P>void comp(int k[],int m,int l)<BR>{<BR> int i=10,j=0,z=1,y=1,x,w,b;<BR> for(w=0;w<m;w++)<BR>for(x=0;x<10;x++)<BR>{<BR> b=-1;<BR>}<BR> while(z>0)<BR> {<BR>z=l/i;<BR>i=i*10;<BR>++j;//记录最大数的位数<BR> }<BR> i=10;<BR> while(j>0)<BR> {<BR>for(z=0;z<=m;z++)<BR>{<BR> x=(k/y)%i;<BR> b=k;<BR>}<BR>w=0;<BR>for(z=0;z<10;z++)<BR> for(x=0;x<m;x++)<BR> {<BR> if(b>=0)<BR> {<BR> k=b;<BR> b=-1;<BR> w++;<BR> }<BR> }<BR>--j;<BR>y=y*10;<BR> }<BR> for(z=0;z<m;z++)<BR> {<BR>printf("%d ",k);<BR> }<BR>}</P>
<P>main()<BR>{<BR> int n,m=0,l=0;<BR> int a;<BR> printf("请输入正整数,负数表示结束:");<BR> scanf("%d",&n);<BR> while(n>=0)<BR> {<BR>a=n;<BR>++m;<BR>if(n>l)<BR> l=n;//记录最大数<BR>scanf("%d",&n);<BR> }</P>
<P> comp(a,m,l);<BR>}</P>
读写文本文件.c
<P>#include "stdio.h"<BR>void main()<BR>{<BR> FILE *funny,*printer,*fp;<BR> char c;</P><P> funny = fopen("TENLINES.TXT","r"); /*打开文本文件 */<BR> printer = fopen("PRN","w"); /*开启打印机*/<BR> fp = fopen("weew.TXT","w");<BR> do{<BR> c = getc(funny); /* 从文件中得到一个字符 */<BR> if(c != EOF)<BR> {<BR> putchar(c); //屏幕上显示字符<BR> putc(c,printer); // 打印机上打印字符<BR> <BR> }<BR> }while (c != EOF); /*重复直到 EOF (end of file)*/<BR> fprintf(fp,"%s",*funny);<BR> fclose(funny);<BR> fclose(printer);<BR> fclose(fp);//关闭打印机<BR>}<BR></P>
文件复制.c
<P>#include<stdio.h><BR>#include<stdlib.h></P><P>void main(int argc,char *argv[])<BR>{<BR> FILE *in,*out;</P>
<P> if(argc!=3){<BR> printf("\n Usage: Hcopy sourcefile targetfile.\n");<BR> exit(1);<BR> }<BR> if((in=fopen(argv,"rb"))==NULL){<BR> printf("\n Cannot open the source file.\n");<BR> exit(2);<BR> }<BR> if((out=fopen(argv,"wb"))==NULL){<BR> printf("\n Cannot open the targetfile.\n");<BR> exit(3);<BR> }</P>
<P> /* start copy */<BR> while(!feof(in))<BR> putc(getc(in),out);</P>
<P> fclose(in);<BR> fclose(out);<BR>}</P>
文件加密.c
<P>给文件加密的技术很多,其中又分为不同等级,以适合不同场合的需要.这里给出最简单的文件加密技术,即采用文件逐字节与密码异或方式对文件进行加密,当解密时,只需再运行一遍加密程序即可.</P><P>下面是一个实例程序,能对任意一个文件进行加密,密码要求用户输入,限8位以内(当然你可以再更改).程序有很好的容错设计,这是我们应该学习的.</P>
<P>/* Turbo 2.0 pass. give file a password! */</P>
<P>#include<stdio.h><BR>#include<stdlib.h><BR>#include<conio.h><BR>#include<string.h></P>
<P>void dofile(char *in_fname,char *pwd,char *out_fname);/*对文件进行加密的具体函数*/</P>
<P>void main(int argc,char *argv[])/*定义main()函数的命令行参数*/<BR>{<BR> char in_fname;/*用户输入的要加密的文件名*/<BR> char out_fname;<BR> char pwd;/*用来保存密码*/</P>
<P> if(argc!=4){/*容错处理*/<BR> printf("\nIn-fname:\n");<BR> gets(in_fname);/*得到要加密的文件名*/</P>
<P> printf("Password:\n");<BR> gets(pwd);/*得到密码*/</P>
<P> printf("Out-file:\n");<BR> gets(out_fname);/*得到加密后你要的文件名*/<BR> </P>
<P>dofile(in_fname,pwd,out_fname);<BR> }<BR> else{/*如果命令行参数正确,便直接运行程序*/<BR> strcpy(in_fname,argv);<BR> strcpy(pwd,argv);<BR> strcpy(out_fname,argv);<BR> dofile(in_fname,pwd,out_fname);<BR> }</P>
<P>}</P>
<P><BR>/*加密子函数开始*/<BR>void dofile(char *in_fname,char *pwd,char *out_file)<BR>{<BR> FILE *fp1,*fp2;<BR> register char ch;<BR> int j=0;<BR> int j0=0;</P>
<P> fp1=fopen(in_fname,"rb");<BR> if(fp1==NULL){<BR> printf("cannot open in-file.\n");<BR> exit(1);/*如果不能打开要加密的文件,便退出程序*/<BR> }<BR> fp2=fopen(out_file,"wb");<BR> if(fp2==NULL){<BR> printf("cannot open or create out-file.\n");<BR> exit(1);/*如果不能建立加密后的文件,便退出*/<BR> }<BR> while(pwd[++j0]);<BR> ch=fgetc(fp1);</P>
<P>/*加密算法开始*/<BR> while(!feof(fp1)){<BR> fputc(ch^pwd,fp2);/*异或后写入fp2文件*/<BR> ch=fgetc(fp1);<BR> }<BR> fclose(fp1);/*关闭源文件*/<BR> fclose(fp2);/*关闭目标文件*/<BR>}</P>
<P>/*程序结束*/</P>
文件连接.c
<P>/****************fcat.c***************/</P><P>#include<stdio.h><BR>#include<stdlib.h><BR>#define BUFSIZE 256</P>
<P>void main(int argc,char *argv[])<BR>{<BR> int i;<BR> char buff;<BR> FILE *fp1,*fp2;</P>
<P> if(argc==1){<BR> printf("Rsage: fcat filename linke_fname.");<BR> printf("\n");<BR> exit(1);<BR> }<BR> if((fp1=fopen (argv,"a"))==NULL){<BR> printf("file %s cannot opened.\n",argv);<BR> exit(1);<BR> }<BR> for(i=2;i<argc;i++){<BR> if((fp2=fopen(argv,"r"))==NULL){<BR> printf("file %s cannot opened.\n");<BR> exit(1);<BR> }<BR> while(fgets(buff,BUFSIZE,fp2)!=NULL)<BR> fputs(buff,fp1);<BR> fclose(fp2);<BR> }<BR> fclose(fp1);<BR>}</P>
网络最短路径Dijkstra算法.c
<P>/*<BR>* File: shortest.c<BR>* Description: 网络中两点最短路径 Dijkstra 算法<BR>* Shortest Path Dijkstra Algorithm<BR>* Created: 2001/11/25<BR>* Author: Justin Hou <BR>*/</P><P>#include <stdio.h><BR>#define true1<BR>#define false 0<BR>#define I9999 /* 无穷大 */<BR>#define N20 /* 城市顶点的数目 */</P>
<P>int cost = {<BR> {0,3,I,I,I,1,I,I,I,I,I,I,I,I,I,I,I,I,I,I},<BR> {3,0,5,I,I,I,6,I,I,I,I,I,I,I,I,I,I,I,I,I},<BR> {I,5,0,4,I,I,I,1,I,I,I,I,I,I,I,I,I,I,I,I},<BR> {I,I,4,0,2,I,I,I,6,I,I,I,I,I,I,I,I,I,I,I},<BR> {I,I,I,2,0,I,I,I,I,7,I,I,I,I,I,I,I,I,I,I},<BR> {1,I,I,I,I,0,1,I,I,I,2,I,I,I,I,I,I,I,I,I},<BR> {I,6,I,I,I,1,0,6,I,I,I,7,I,I,I,I,I,I,I,I},<BR> {I,I,1,I,I,I,6,0,2,I,I,I,3,I,I,I,I,I,I,I},<BR> {I,I,I,6,I,I,I,2,0,8,I,I,I,4,I,I,I,I,I,I},<BR> {I,I,I,I,7,I,I,I,8,0,I,I,I,I,5,I,I,I,I,I},<BR> {I,I,I,I,I,2,I,I,I,I,0,4,I,I,I,3,I,I,I,I},<BR> {I,I,I,I,I,I,7,I,I,I,4,0,3,I,I,I,4,I,I,I},<BR> {I,I,I,I,I,I,I,3,I,I,I,3,0,3,I,I,I,5,I,I},<BR> {I,I,I,I,I,I,I,I,4,I,I,I,3,0,7,I,I,I,2,I},<BR> {I,I,I,I,I,I,I,I,I,5,I,I,I,7,0,I,I,I,I,3},<BR> {I,I,I,I,I,I,I,I,I,I,3,I,I,I,I,0,5,I,I,I},<BR> {I,I,I,I,I,I,I,I,I,I,I,4,I,I,I,5,0,8,I,I},<BR> {I,I,I,I,I,I,I,I,I,I,I,I,5,I,I,I,8,0,6,I},<BR> {I,I,I,I,I,I,I,I,I,I,I,I,I,2,I,I,I,6,0,4},<BR> {I,I,I,I,I,I,I,I,I,I,I,I,I,I,3,I,I,I,4,0}<BR>};<BR>int dist; /* 存储当前最短路径长度 */<BR>int v0 = 'A' - 65; /* 初始点是 A */</P>
<P>void main()<BR>{<BR> int final, i, v, w, min;</P>
<P> /* 初始化最短路径长度数据,所有数据都不是最终数据 */<BR> for (v = 0; v < N; v++) {<BR> final = false;<BR> dist = cost;<BR> }</P>
<P> /* 首先选v0到v0的距离一定最短,最终数据 */<BR> final = true;</P>
<P> /* 寻找另外 N-1 个结点 */<BR> for (i = 0; i < N-1; i++) {<BR> min = I; /* 初始最短长度无穷大*/<BR> <BR> /* 寻找最短的边 */<BR> for (w = 0; w < N; w++) {<BR> if (!final && dist < min) {<BR> min = dist;<BR> v = w;<BR> }<BR> }<BR> final = true; /* 加入新边 */</P>
<P> for (w = 0; w < N; w++) { /* 更新 dist[] 数据*/<BR> if (!final && dist + cost < dist) {<BR> dist = dist + cost;<BR> }<BR> }<BR> }</P>
<P> for (i = 0; i < N; i++) { /* 显示到监视器 */<BR> printf("%c->%c: %2d\t", v0 + 65, i + 65, dist);<BR> }<BR>}</P>
矩阵乘法动态规划.c
<P>/*<BR>* File: multi.c<BR>* Description:矩阵乘法动态规划<BR>* Created: 10:20 2001-12-3<BR>* Author: Justin Hou <BR>*<BR>*/</P><P>#include <stdio.h><BR>#defineN7</P>
<P>int middle;</P>
<P>void Show(int, int);</P>
<P>void main()<BR>{<BR> int i, j, l, k;<BR> unsigned long m, min;<BR> int r = {10, 20, 50, 1, 100, 4, 20, 2}; /* 矩阵维数 */</P>
<P> /* 初始化 */<BR> for (i = 1; i <= N; i++) {<BR> m = 0;<BR> }<BR> /* 每此增量加一 */<BR> for (l = 1; l < N; l++) {</P>
<P> /* 对于差值为 l 的两个元素 */<BR> for (i = 1; i <= N - l; i++) {<BR> j = i + l; </P>
<P> /* 求其最小组合方式 */<BR> min = m + m + r * r * r;<BR> middle = i;<BR> for (k = i + 1; k < j; k++) {<BR> if (min > m + m + r * r * r) {<BR> min = m + m + r * r * r;<BR> middle = k;<BR> }<BR> }<BR> m = min;<BR> }<BR> }<BR> printf("M = ");<BR> Show(1, N);<BR> printf("\nMultiply Count: %d\n", m);<BR>}<BR> <BR>void Show(int i, int j)<BR>{<BR> int k, m;</P>
<P> if (i == j){<BR> printf("M%d", i); /* 如果下一个是矩阵,输出*/<BR> }<BR> else {<BR> m = middle; /* 分割成左右两组 */<BR> if (i != m) printf("("); /* 如果下一个显示的不是矩阵 */<BR> Show(i, m); /* 显示左边的内容 */<BR> if (i != m) printf(")"); /* 如果上一个显示的不是矩阵 */<BR> printf(" x "); /* 打印乘法符号 */<BR> if (m+1 != j) printf("("); /* 如果下一个显示的不是矩阵 */<BR> Show(m + 1, j); /* 显示右边的内容 */<BR> if (m+1 != j) printf(")"); /* 如果下一个显示的不是矩阵 */<BR> }</P>
<P>}</P>
万年历.c
<P>#include "stdio.h" /* Required for MS-DOS use */ <BR>#define ENTER 0x1C0D/* Enter key */ <BR>int year, month, day; <BR>static char *days = {" ","Sunday ","Monday ","Tuesday", <BR> "Wednesday","Thursday ","Friday ","Saturday "}; <BR>struct TIMEDATE { <BR> int year; /* year 1980..2099 */ <BR> int month; /* month 1=Jan 2=Feb, etc. */ <BR> int day; /* day of month 0..31 */ <BR> int hours; /* hour 0..23 */ <BR> int minutes; /* minute 0..59 */ <BR> int seconds; /* second 0..59 */ <BR> int hsecs; /* 1/100ths of second 0..99 */ <BR> char dateline; /* date & time together */ <BR> }; <BR>static struct TIMEDATE today; <BR>main() <BR> { <BR>char cmonth; <BR>char cday; <BR>char cyear; <BR>double getdays(); <BR>double daynumb, numbnow; <BR>int weekday, retcode, dayer, i; <BR>dayer = datetime(&today); <BR>clrscn(); <BR>for (i=0;i<3;++i)cmonth='\0'; <BR>for (i=0;i<3;++i)cday='\0'; <BR>for (i=0;i<5;++i)cyear='\0'; <BR>putstr(5,8,14,"Enter date in MM DD YYYY format:"); <BR>while (retcode != ENTER) <BR> { <BR> retcode = bufinp(5,41,13,2,cmonth); <BR> if (retcode != ENTER) retcode = bufinp(5,44,13,2,cday); <BR> if (retcode != ENTER) retcode = bufinp(5,47,13,4,cyear); <BR> } <BR>year = atoi(&cyear); <BR>month = atoi(&cmonth); <BR>day = atoi(&cday); <BR>daynumb = getdays(year, month, day); <BR>numbnow = getdays(today.year, today.month, today.day); <BR>weekday = weekdays(daynumb); <BR>if (numbnow - daynumb == 0) <BR> printf("\n\n%02d-%02d-%d is",month, day, year); <BR>if (numbnow - daynumb > 0) <BR> printf("\n\n%02d-%02d-%d was",month, day, year); <BR>if (numbnow - daynumb < 0) <BR> printf("\n\n%02d-%02d-%d will be",month, day, year); <BR>printf(" a %s\n",days); <BR> }/* end MAIN */ <BR>/************************************************************ <BR> * GETDAYS- From integer values of year (YYYY), month * <BR> * (MM) and day (DD) this subroutine returns a * <BR> * double float number which represents the * <BR> * number of days since Jan 1, 1980 (day 1). * <BR> * This routine is the opposite of GETDATE. * <BR> ************************************************************/ <BR> double getdays(year, month, day) <BR>int year, month, day; <BR>{ <BR> int y,m; <BR> double a,b,d, daynumb; <BR> double floor(),intg(); <BR> /********************************** <BR> ** make correction for no year 0 ** <BR> **********************************/ <BR> if (year < 0) y = year + 1; <BR> else y = year; <BR> /********************************************************* <BR> ** Jan and Feb are months 13 and 14 in this calculation ** <BR> *********************************************************/ <BR> m = month; <BR> if (month < 3) <BR> { <BR> m = m + 12; <BR> y = y - 1; <BR> } <BR> /************************** <BR> ** calculate Julian days ** <BR> **************************/ <BR> d = floor(365.25 * y) + intg(30.6001 * (m + 1)) + day - 723244.0; <BR> /********************************************** <BR> ** use Julian calendar if before Oct 5, 1582 ** <BR> **********************************************/ <BR> if (d < -145068.0) daynumb = d; <BR> /************************************* <BR> ** otherwise use Gregorian calendar ** <BR> *************************************/ <BR> else <BR> { <BR> a = floor(y / 100.0); <BR> b = 2 - a + floor(a / 4.0); <BR> daynumb = d + b; <BR> } <BR> return(daynumb); <BR> } /* end GETDAYS */ <BR>/******************************************************** <BR> * GETDATE - This routine takes a double float number * <BR> * representing the number of days since Jan 1,* <BR> * 1980 (day 1) and returns the year month and * <BR> * day as pointer integers * <BR> * This routine is the opposite of GETDAYS * <BR> ********************************************************/ <BR> getdate(numb) <BR> double numb; <BR> { <BR> double a,aa,b,c,d,e,z; <BR> double date; <BR><BR> date = numb; <BR> z = intg(date + 2444239.0); <BR> if (date < -145078.0) a = z; <BR> else <BR> { <BR> aa = floor((z - 1867216.25) / 36524.25); <BR> a = z + 1 + aa - floor(aa/4.0); <BR> } <BR> b = a + 1524.0; <BR> c = intg((b - 122.1) / 365.25); <BR> d = intg(365.25 * c); <BR> e = intg((b - d) / 30.6001); <BR> day = b - d - intg(30.6001 * e); <BR> if (e > 13.5) month = e - 13.0; <BR> else month = e - 1.0; <BR> if (month > 2) year = c - 4716.0; <BR> else year = c - 4715.0; <BR> if (year < 1) --year; <BR> return; <BR> } /* end GETDATE */ <BR>/******************************************************** <BR> * WEEKDAYS - This routine takes a double float number* <BR> * representing the number of days since Jan 1,* <BR> * 1980 (day 1) and returns the day of the week* <BR> * where 1 = Sunday, 2 = Tuesday, etc. * <BR> ********************************************************/ <BR> int weekdays(numb) <BR> double numb; <BR> { <BR> double dd; <BR> int day; <BR><BR> dd = numb; <BR> while (dd > 28000.0) dd = dd - 28000.0; <BR> while (dd < 0) dd = dd + 28000.0; <BR> day = dd; <BR> day = ((day + 1) % 7) + 1; <BR> return(day); <BR> } <BR>/******************************************************** <BR> * FRACT -This routine takes a double float number * <BR> * and returns the fractional part as a double * <BR> * float number * <BR> ********************************************************/ <BR> double fract(numb) <BR> double numb; <BR> { <BR> int inumb; <BR> double fnumb; <BR><BR> while (numb < -32767) numb += 32767; <BR> while (numb > 32767) numb -= 32767; <BR> inumb = numb; <BR> fnumb = inumb; <BR> return(numb-fnumb); <BR> } /* end FRACT */ <BR>/******************************************************** <BR> * FLOOR -This routine takes a double float number * <BR> * and returns the next smallest integer * <BR> ********************************************************/ <BR> double floor(numb) <BR> double numb; <BR> { </P><P> double fract(), intg(); <BR> double out; <BR> out = intg(numb); <BR> if (numb < 0 && fract(numb) != 0) out -= 1.0; <BR> return(out); <BR> } /* end FLOOR */ <BR>/******************************************************** <BR> * INTG-This routine takes a double float number * <BR> * and returns the integer part as a double * <BR> * float number * <BR> ********************************************************/ <BR> double intg(numb) <BR> double numb; <BR> { <BR> double fract(); <BR> return(numb - fract(numb)); <BR> } /* end INTG */</P>