< C语言数值算法程序大全>>配套程序

源代码在线查看: xfactln.c

软件大小: 834 K
上传用户: tanghui2008
关键词: gt 程序 lt C语言
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* Driver for routine factln */
				
				#include 
				#include 
				#include 
				#include 
				#define NRANSI
				#include "nr.h"
				#include "nrutil.h"
				
				#define MAXSTR 80
				
				int main(void)
				{
					char txt[MAXSTR];
					int i,n,nval;
					float val;
					FILE *fp;
				
					if ((fp = fopen("fncval.dat","r")) == NULL)
						nrerror("Data file fncval.dat not found\n");
					fgets(txt,MAXSTR,fp);
					while (strncmp(txt,"N-factorial",11)) {
						fgets(txt,MAXSTR,fp);
						if (feof(fp)) nrerror("Data not found in fncval.dat\n");
					}
					fscanf(fp,"%d %*s",&nval);
					printf("\nlog of n_factorial\n");
					printf("\n%6s %19s %21s\n","n","actual","factln(n)");
					for (i=1;i						fscanf(fp,"%d %f",&n,&val);
						printf("%6d %20.7f %20.7f\n",n,log(val),factln(n));
					}
					fclose(fp);
					return 0;
				}
				#undef NRANSI
							

相关资源