1、conio.hstdio.hvoid readwriteDAT() ;int isP(int m) int i ; for(i = 2 ; i m ; i+) if(m % i = 0) return 0 ; return 1 ;main() int m, n, xx1000 ; clrscr() ; printf(nPlease enter two integers:) ; scanf(%d,%d, &m, &n ) ; num(m, n, xx) ; for(m = 0 ; m n ; m+)%d , xxm) ;n readwriteDAT() ;system(pause);void r
2、eadwriteDAT() int m, n, xx1000, i ; FILE *rf, *wf ; rf = fopen(in.dat, r wf = fopen(out.datw for(i = 0 ; 10 ; i+) fscanf(rf, %d %dn) ; m+) fprintf(wf, fprintf(wf, fclose(rf) ; fclose(wf) ;IN.DAT17 5101 7321 532 455 676 699 4781 522 666 3OUT.DAT19 23 29 31 37 103 107 109 113 127 131 137 331 337 347 3
3、49 353 37 41 43 47 59 61 67 71 73 79 79 83 89 97 101 103 101 103 107 109 787 797 809 811 821 23 29 31 37 41 43 67 71 732题目: 题目2:已知数据文件IN.DAT中存有200个四位数, 并已调用读函数readDat()把这些数存入数组a中,请考生编制一函数jsVal(),其功能是: 如果四位数各位上的数字均是0或2或4或6或8, 则统计出满足此条件的个数cnt, 并把这些四位数按从大到小的顺序存入数组b中。最后main()函数调用写函数writeDat( )把结果cnt以及数组
4、b中符合条件的四位数输出到OUT.DAT文件中。 注意: 部分源程序存在文件PROG1.C文件中。 程序中已定义数组: a200, b200, 已定义变量: cnt 请勿改动数据文件IN.DAT中的任何数据、主函数main()、读函数readDat()和写函数writeDat()的内容。-void jsVal() /*标准答案*/int bb4;int I,j,k,flag;for (I=0;200; bb0=aI/1000; bb1=aI%1000/100; bb2=aI%100/10; bb3=aI%10; for (j=0;4; if (bbj%2=0) flag=1; else fla
5、g=0;break; if (flag=1) bcnt=aI; cnt+;for(I=0;cnt-1; for(j=I+1;cnt; if (bIbj) k=bI;bI=bj;bj=k;PROG1.C#define MAX 200int aMAX, bMAX, cnt = 0;void jsVal()void readDat() FILE *fp ; fp = fopen( MAX ; i+) fscanf(fp, %dai) ; fclose(fp) ;void main() readDat() ; jsVal() ;满足条件的数=%dn, cnt) ; cnt ; i+) printf(,
6、 bi) ; writeDat() ;writeDat() FILE *fp ; int i ; fprintf(fp, %dn i+) fprintf(fp, 601250999012702580887055533476078145579528963019774770904140862679053735962087149496364052497671592546872982622764782638279382988246589298619110226969519800243953391064999467625752100110307989284529583820301094869798401
7、427831604162864664101412871273262633220761860583445809057261478523789289791946317627642855610694591378348543491624303677950255137463035354048269724389791390336504899155747452573628854211563938565455061390510747840459675375961832721041055331712825368657154408274191967894542357015007044928853027577401
8、846194922329758981699927644392729872575076736256632277901297323534805254634064824206086455886754992793310542963444100960411469234620234771492480021949937130434545477923053824064847282626724721999683398103题目: 题目3:函数READDAT()实现从文件IN.DAT中读取一篇英文文章存入到字符串数组XX中;请编制函数STROR(),其函数功能是:以行为单位把字符串中的所有小写字母O左边的字符串内
9、容移到该串的右边存放,然后并把小写字母O删除,余下的字符串内容移到已处理字符串的左边存放.最后把已处理的字符串仍按行重新存入字符串数组XX中,最后调用函数WRITEDAT()把结果XX输出到文件OUT.DAT中.例如:原文:You can create an index on any field. you have the correct record. 结果: n any field.You can create an index rd.yu have the crrect rec 原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格.-字符串(单词)的倒置和删除。答案:v
10、oid StrOR(void) /*标准答案*/int I,j,k,index,strl; char ch; for(I=0;maxline; strl=strlen(xxI); index=strl; for(j=0;strl; if(xxIj=o) for(k=j;k=index;j-)ch=xxIstrl-1; for(k=strl-1;k-)xxIk=xxIk-1;xxI0=ch;void StrOR(void) int i; char a80,*p; for(i=0;i=xxi) p1-;memcpy(t1,p1+1,p2-p1);t1p2-p1=0;strcat(t,t1);str
11、cat(t, if(p1xxi) k=0;strcpy(xxi,t);# includestdio.hstring.hconio.hchar xx5080;int maxline=0;int ReadDat(void);void WriteDat(void);void StrOR(void) clrscr();if(ReadDat()printf(Cant open the file!return;StrOR();WriteDat();int ReadDat(void)FILE *fp;int i=0;char *p;if(fp=fopen(,)=NULL) return 1;while(fg
12、ets(xxi,80,fp)!=NULL)p=strchr(xxi,nif(p) *p=0;i+;maxline=i;fclose(fp);return 0;void WriteDat(void)int i;fp=fopen(%sn,xxi);fprintf(fp,you have the correct record.You can create an index on any field, on several fields to be usedtogether, or on parts thereof, that you want to use as a key. Thekeys in
13、indexes allow you quick access to specific records and defineorders for sequential processing of a ISAM file. After you no longerneed an index, you can delete it. Addition and indexes have no effecton the data records or on other indexes.You may want a field in field in each record to uniquely ident
14、ify thatrecord from all other records in the file. For example, the EmployeeNumber field is unique if you do not assign the same number to twodifferent employees, and you never reassign these numbers to otheremployees. If you wish to find or modify the record belonging to aspecific employee, this un
15、ique field saves the thouble of determiningwhether you have the correct record.If you do not have a unique field, you must find the first recordthe matches your key and determine whether the record is the one youwant. If it is not the correct one, you must search again to find others.If you know tha
16、t you have a unique field within your records, youcan include this fact in the key description, and ISAM will allow onlyunique keys. For example, if you specify that the employee numbers areunique, ISAM only lets you add records to the file for, or changenumbers to, employee numbers that do not alre
17、adly exist int file.n any field. Yu can create an index rd. yu have the crrect rec be used Yu can create an index n any field, n several fields t use as a key. The tgether, r n parts theref, that yu want trds and define keys in indexes allw yu quick access t specific recnger rders fr sequential prce
18、ssing f a ISAM file. After yu n l effect need an index, yu can delete it. Additin and indexes have nther indexes. n the data recrds r n uniquely identify that Yu may want a field in field in each recrd tyee recrd frm all ther recrds in the file. Fr example, the Empl Number field is unique if yu d nt assign the same number t twther different emplyees, and yu never reassign these numbers t a emplyees. If yu wish t find r mdify the recrd belnging tf determining specific emplyee, this u
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1