全文预览

《算法分析与设计》实验教学大纲

上传者:似水流年 |  格式:doc  |  页数:11 |  大小:187KB

文档介绍
部文件为knapsack-input.txt:2,读入文件的操作:FILE*fp;/*Openforread(willfailiffile"knapsack-input.txt"doesnotexist)*/if((fp=fopen("knapsack-input.txt","r"))==NULL)printf("Thefile'knapsack-input.txt'wasnotopened\n");elseprintf("Thefile'knapsack-input.txt'wasopened\n");//读输入文件,写n,M,p[MAX],w[MAX]?fscanf(fp,"n=%d\n",&n);?fscanf(fp,"M=%d\n",&M); for(i=0;i<n;i++) fscanf(fp,"%f",&profit[i]);?fscanf(fp,"\n"); for(i=0;i<n;i++) fscanf(fp,"%f",&weight[i]);?fscanf(fp,"\n");/*Closestream*/if(fclose(fp))printf("Thefile'knapsack-input.txt'wasnotclosed\n");附录2关于如何统计运算时间#include"time.h"…….//?----starttime-----设置计时开始?doubleduration;clock_tfinish,start;?start=clock();……//?----finishtime-----设置计时结束?finish=clock();duration=(double)(finish-start)/CLOCKS_PER_SEC;//统计时间durationprintf("\nTheCPUtimeis%2.6fseconds:\n",duration);

收藏

分享

举报
下载此文档