1、 1mmkxxnum(int m,int k,int xx) readwriteDAT()out.dat 磺1751923293137 main()readwriteDAT()-void num(int m,int k,int xx) /*/int data=m+1;int half,n=0,I; while(1) half=data/2;for(I=2;Ihalf) xxn=data;n+; if(n=k)break; data+; void num(int m,int k,int xx)int i,j,s=0;for(i=m+1;k0;i+)for(j=2;j0;m+)if(isP(m)
2、xx=m;k-; #include #include void readwriteDAT() ;int isP(int m) int i ;for(i = 2 ; i m ; i+) if(m % i = 0) return 0 ;return 1 ;void num(int m,int k,int xx)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+) printf(%d , xx
3、m) ;printf(n) ;readwriteDAT() ;system(pause);void readwriteDAT() int m, n, xx1000, i ;FILE *rf, *wf ;rf = fopen(in.dat, r) ;wf = fopen(out.dat, w) ;for(i = 0 ; i 10 ; i+) fscanf(rf, %d %d, &m, &n) ; num(m, n, xx) ; for(m = 0 ; m n ; m+) fprintf(wf, %d , xxm) ; fprintf(wf, n) ;fclose(rf) ;fclose(wf)
4、; 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 349 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 73 2 2IN.DAT200, readDat()a,jsVal(),书: 02468, cnt, bmain()writeDat( )
5、cntbOUT.DAT : PROG1.C : a200, b200, : cnt IN.DATmain()readDat()writeDat()-void jsVal() /*/int bb4;int I,j,k,flag;for (I=0;I200;I+)bb0=a/1000; bb1=a%1000/100; bb2=a%100/10; bb3=a%10; for (j=0;j4;j+) if (bbj%2=0) flag=1; else flag=0;break; if (flag=1) bcnt=a; cnt+; for(I=0;Icnt-1;I+) for(j=I+1;jcnt;j+
6、) if (bbj) k=b;b=bj;bj=k;PROG1.C#include #define MAX 200int aMAX, bMAX, cnt = 0;void jsVal()void readDat() int i ; FILE *fp ; fp = fopen(in.dat, r) ; for(i = 0 ; i MAX ; i+) fscanf(fp, %d, &a) ; fclose(fp) ;void main() int i ; readDat() ; jsVal() ; printf(=%dn, cnt) ; for(i = 0 ; i cnt ; i+) printf(
7、%d , b) ; printf(n) ; writeDat() ;system(pause);writeDat() FILE *fp ; int i ; fp = fopen(out.dat, w) ; fprintf(fp, %dn, cnt) ; for(i = 0 ; i cnt ; i+) fprintf(fp, %dn, b) ; fclose(fp) ;IN.DAT6012509990127025808870555334760781456012509990127025808870555334579528963019774776078145709041408626790537359
8、620871494963640524976715925468729826227647826382793829882465892986157952896301977477607814560125099901270258088705553345795289630197747760781457090414086267905373596208714949636405249767159254687298262276478263827938298824658929861911022696951980024395339106499946762575210011030798928452958382030109
9、486979840142783160416286466410141287127326263322076186058344580905726147852378928979194631762764285561069459137834854349162430367795025513746303535404826972438979139033650489915574745257362885421156393856545506139051074784045967537596183272104105533171282536865715440827419196789454235701500704492885
10、302757740184619492220763297589816999276443927298725750727296736256632277901297323534805254634064824206086455886754992793310542963444100960411469234620234771492480021949937130434545477923053824064847282626724721999683398OUT.DAT1086268626824682468088808880886466628840483 3READDATIN.DATXX;STROR(),亯:O,&
11、#993456;O,.XX,WRITEDAT()XXOUT.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,.-𰸣void StrOR(void) /*/int I,j,k,index,strl;char ch;for(I=0;Imaxline;I+) strl=strlen(xx); index=strl; for(j=0;jstrl;j+) if
12、(xxj=o) for(k=j;k=index;j-)ch=xxstrl-1;for(k=strl-1;k0;k-)xxk=xxk-1;xx0=ch; void StrOR(void) int i;char a80,*p;for(i=0;imaxline;i+) p=strchr(xx,o); while(p) memset(a,0,80); memcpy(a,xx,p-xx); strcpy(xx,p+1); strcat(xx,a); p=strchr(xx,o); void StrOR(void) /*/int i,righto,j,k;char tem80;for(i=0;i=0;j-
13、) if(xxj=o) righto=j;break; for(j=righto+1;jstrlen(xx);j+) temk+=xxj;for(j=0;jrighto;j+) if(xxj!=o) temk+=xxj;strcpy(xx,tem);oowhile()p1octrcat()p1tstrcat()p1t棨p1p1*p1=0while()oovoid StrOR(void)int i;char *p1,*p2,t80;for(i=0;imaxline;i+)t0=0;p2=xx;while(*p2)if(*p2=o) p1=p2;p2+;strcat(t,p1+1);*p1=0;s
14、trcat(t,xx);p1=xx;p2=t;while(*p2)if(*p2!=o) *p1+=*p2;p2+;*p1=0;p1p1+1p2(t1)t1tvoid Str0L(void)int i,k;char *p1,*p2;char t80,t180;for(i=0;i=xx) p1-;memcpy(t1,p1+1,p2-p1);t1p2-p1=0;strcat(t,t1);strcat(t, );if(p1xx) k=0;strcpy(xx,t);PROG1.C# includestdio.h# includestring.h# includeconio.hchar xx5080;in
15、t maxline=0;int ReadDat(void);void WriteDat(void);void StrOR(void) void main()clrscr();if(ReadDat()printf(Cant open the file!n);return;StrOR();WriteDat();system(pause);int ReadDat(void)FILE *fp;int i=0;char *p;if(fp=fopen(in.dat,r)=NULL) return 1;while(fgets(xx,80,fp)!=NULL)p=strchr(xx,n);if(p) *p=0
16、;i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;fp=fopen(out.dat,w);for(i=0;imaxline;i+)printf(%sn,xx);fprintf(fp,%sn,xx);fclose(fp);IN.DATYou can create an index on any field.you have the correct record.You can create an index on any field, on several fields to be usedtogether,
17、or on parts thereof, that you want to use as a key. Thekeys in 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
18、.You may want a field in field in each record to uniquely identify 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 fin
19、d or modify the record belonging to aspecific employee, this unique 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 co
20、rrect one, you must search again to find others.If you know that 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 f
21、ile for, or changenumbers to, employee numbers that do not alreadly exist int file. OUT.DATn any field. Yu can create an index rd. yu have the crrect recbe used Yu can create an index n any field, n several fields tuse as a key. The tgether, r n parts theref, that yu want trds and define keys in ind
22、exes allw yu quick access t specific recnger rders fr sequential prcessing f a ISAM file. After yu n leffect 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
23、 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 unique field saves the thuble rd. whether yu h
24、ave the crrect recrd If yu d nt have a unique field, yu must find the first recu the matches yur key and determine whether the recrd is the ne ythers. want. If it is nt the crrect ne, yu must search again t find u If yu knw that yu have a unique field within yur recrds, ynly can include this fact in
25、 the key descriptin, and ISAM will allw yee numbers are unique keys. Fr example, if yu specify that the emplr change unique, ISAM nly lets yu add recrds t the file fr, t alreadly exist int file. numbers t, emplyee numbers that d n4 4ReadDat( )IN.DATxx; StrOL( ), 亯: ()xxmain()WriteDat()xxOUT6.DAT : :
26、 You He Me I am a student. : Me He You student a am I : 80, -𰸣void StrOL(void) /*/int I,j,k,strl,l;char c;for(I=0;Imaxline;I+) for(j=0;j=A&c=a&c=z)|c= ) ; else xxj= ; for(l=0;l=a&xxl=A&xxl=0)for(j=k;j=0;j-)ppj+1=ppj; pp0=xxl; k+;I-; strcat(ch,pp);strcpy(pp, );k=1;if(I=-1)break; while(xxlz)&I
27、=0) for(j=k;j=0;j-) ppj+1=ppj; pp0=xxl; k+; I-;strcat(ch,pp); strcpy(pp,);k=0;if(I=-1)break;strcpy(xxl,ch); void StrOL(void) int i,j,k,m,n,ll; char yy80; for(i=0; i =0; j-) if(isalpha(xxj) k+; else for(m=1; m=k; m+) yyn+=xxj+m; k=0; if(xxj= ) yyn+= ; for(m=1; m=k; m+) yyn+=xxj+m; yyn=0; strcpy(xx,yy
28、); PROG1.C# includestdio.h# includestring.h# includeconio.h# includectype.hchar xx5080;int maxline=0;int ReadDat(void);void WriteDat(void);void StrOR(void)void main()clrscr();if(ReadDat()printf(Cant open the file!n);return;StrOR();WriteDat();system(pause);int ReadDat(void)FILE *fp;int i=0;char *p;if
29、(fp=fopen(in.dat,r)=NULL) return 1;while(fgets(xx,80,fp)!=NULL)p=strchr(xx,n);if(p) *p=0;i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;fp=fopen(out.dat,w);for(i=0;imaxline;i+)printf(%sn,xx);fprintf(fp,%sn,xx);fclose(fp);IN.DATYou He MeI am a studentYou can create an index on any
30、 field, on several fields to be usedtogether, or on parts thereof, that you want to use as a key. Thekeys in 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
31、 effecton the data records or on other indexes.You may want a field in field in each record to uniquely identify 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
32、 numbers to otheremployees. If you wish to find or modify the record belonging to aspecific employee, this unique 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
33、record is the one youwant. If it is not the correct one, you must search again to find others.If you know that 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 areu
34、nique, ISAM only lets you add records to the file for, or changenumbers to, employee numbers that do not alreadly exist int file. OUT.DATMe He Youstudent a am Iused be to fields several on field any on index an create can YouThe key a as use to want you that thereof parts on or togetherdefine and re
35、cords specific to access quick you allow indexes in keyslonger no you After file ISAM a of processing sequential for orderseffect no have indexes and Addition it delete can you index an needindexes other on or records data the onthat identify uniquely to record each in field in field a want may YouE
36、mployee the example For file the in records other all from recordtwo to number same the assign not do you if unique is field Numberother to numbers these reassign never you and employees differenta to belonging record the modify or find to wish you If employeesdetermining of thouble the saves field
37、unique this employee specificrecord correct the have you whetherrecord first the find must you field unique a have not do you Ifyou one the is record the whether determine and key your matches theothers find to again search must you one correct the not is it If wantyou records your within field uniq
38、ue a have you that know you Ifonly allow will ISAM and description key the in fact this include canare numbers employee the that specify you if example For keys uniquechange or for file the to records add you lets only ISAM uniquefile int exist alreadly not do that numbers employee to numbers5 5in.d
39、at20010009999ReadDat()200aajsSort()亯10bWriteDat()bbout.dat 6012 5099 9012 7025 8088 9012 6012 7025 8088 5099 main()ReadDat()WriteDat() -void jsSort() /*/int I,j,data;for(I=0;I199;I+) for(j=I+1;jaaj%1000) data=aa;aa=aaj;aaj=data; else if(aa%1000=aaj%1000) if(aaaaj) data=aa;aa=aaj;aaj=data; for(I=0;I1
40、0;I+) bb=aa;PROG1.C#include#include#includeint aa200,bb10;void jsSort()void main()readDat();jsSort();writeDat();system(pause);readDat()FILE *in;int i;in=fopen(in.dat,r);for(i=0; i200; i+) fscanf(in,%d,&aa);fclose(in);writeDat()FILE *out;int i;clrscr();out=fopen(out.dat,w);for(i=0; i10; i+)printf(i=%
41、d,%dn,i+1,bb);fprintf(out,%dn,bb);fclose(out);IN.DAT60125099901270258088705553347607814560125099901270258088705553345795289630197747760781457090414086267905373596208714949636405249767159254687298262276478263827938298824658929861579528963019774776078145601250999012702580887055533457952896301977477607
42、814570904140862679053735962087149496364052497671592546872982622764782638279382988246589298619110226969519800243953391064999467625752100110307989284529583820301094869798401427831604162864664101412871273262633220761860583445809057261478523789289791946317627642855610694591378348543491624303677950255137
43、46303535404826972438979139033650489915574745257362885421156393856545506139051074784045967537596183272104105533171282536865715440827419196789454235701500704492885302757740184619492220763297589816999276443927298725750727296736256632277901297323534805254634064824206086455886754992793310542963444100960411469234620234771492480021949937130434545477923053824064847282626724721999683398OUT.DAT1001301090129012901260126012601240144018