资源描述:
《计算机二级c语言考试上级题库答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineN8typedefstructlist{intdata;structlist*next;}SLIST;voidfun(SLIST*p){SLIST*t,*s;t=p->next;s=p;while(t->next!=NULL){s=t;/**********found**********/t=t->next;}/**********found**********/printf("%d",t->data);s->next
2、=NULL;/**********found**********/free(t);}SLIST*creatlist(int*a){SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;idata=a[i];p->next=q;p=q;}p->next=0;returnh;}voidoutlist(SLIST*h){SLIST*p;p=h->next;
3、if(p==NULL)printf("ThelistisNULL!");else{printf("Head");do{printf("->%d",p->data);p=p->next;}while(p!=NULL);printf("->End");}}main(){SLIST*head;inta[N]={11,12,15,18,19,22,25,29};head=creatlist(a);printf("Outputfromhead:");outlist(head);print
4、f("Outputfromtail:");while(head->next!=NULL){fun(head);printf("");printf("Outputfromheadagain:");outlist(head);}}#include/************found************/fun(char*a){if(*a){fun(a+1);/************found************/printf("%c",*a);}}mai
5、n(){chars[10]="abcd";printf("处理前字符串=%s处理后字符串=",s);fun(s);printf("");}#includechar*fun(char*s,char*t){inti;char*p=s,*q=t;for(i=0;*p&&*q;i++){p++;q++;}if(*p==0&&*q==0)returns;if(*p)returns;elsereturnt;}main(){chara[20],b[20];printf("Input1ths
6、tring:");gets(a);printf("Input2thstring:");gets(b);printf("%s",fun(a,b));NONO();}NONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;inti;chara[20],b[20];fp=fopen("C:\WEXAM\24990001\in.dat","r");wf=fopen("C:\WEXAM\24990001\out.dat","w");for(i=0
7、;i<10;i++){fscanf(fp,"%s%s",a,b);fprintf(wf,"%s",fun(a,b));}fclose(fp);fclose(wf);}#include#include#defineN8typedefstructlist{intdata;structlist*next;}SLIST;voidfun(SLIST*h){SLIST*p,*q;p=h->next;if(p!=NULL){q=p->next;while(q!=NULL){
8、if(p->data==q->data){p->next=q->next;/**********found**********/free(q);/**********found**********/q=p->next;}else{p=q;/**********found**********/q=q->next;}}}}SLIST*creatlist(int*a){SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(S