二级c语言题库答案.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《二级c语言题库答案.pdf》由会员分享,可在线阅读,更多相关《二级c语言题库答案.pdf(102页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、二 级C语言题库答案第1套题一、程序填空题#include<stdio.h>#include<stdlib.h>#define N 5typedef struct int num;char name10;char tel10;STYPE;void check();/*fou nd*字/int fun(STYPE*std)/*fou nd*/FILE*fp;intif(fp=fopen("myfile5.dat","wb")=NULL)printf("nOutput data to file!n");for(i=
2、0;i<N;i+)/*found*/return(O);fwrite(&stdi,sizeof(STYPE),1,fp);fclose(fp);return(1);二、程序改错题#include<stdio.h>#include<string.h>void fun(char*s,char*t)int i,si;si=strlen(s);/*字 不*字found*亭 亭*/for(i=0;i<=sl;i+)ti=si;for(i=0;i<sl;i+)tsl+i=ssl-i-l;/*found*/tsl+sl=0,;main()char s100,
3、t100;printf("nPIease enter string s:");scanf("%s",s);fun(s,t);printf("The result is:%sn",t);)第2套题一、程序填空题#include<stdio.h>#include<string.h>#include<stdlib.h>void WriteText(FILE*);void ReadText(FILE*);main()FILE*fp;if(fp=fopen("myfile4.txt",&q
4、uot;w")=NULL)printf("openfail!n");exit(O);WriteText(fp);fclose(fp);if(fp=fopen("myfile4.txt","r")=NULL)printf("openfail!n");exit(O);ReadText(fp);fclose(fp);/*;jcfound*/void WriteText(FILE*fw)char str81;printf("nEnter string with-1 to end:n");get
5、s(str);while(strcmp(str,"-1")!=0)/*found*/fputs(str,fw);fputs("n",fw);gets(str);void ReadText(FILE*fr)char str81;printf("nRead file and output to screen:n");fgets(str,81,fr);while(!feof(fr)/*tound*/printf("%s",str);fgets(str,81,fr);二、程序改错题#include<stdio.h&g
6、t;long sl=10;*t=s%10;while(s>0)s=s/100;*t=s%10*si+*t;main()long s,t;printf("nPlease enter s:");scanf("%ld",&s);fun(s,&t);printf("The result is:%ldn",t);)第 3 套题一、程序填空题#include<math.h>#include<stdio.h>int fun(char*fname)FILE*fp;int i,n;float x;if(fp
7、=fopen(fname,"w")=NULL)return 0;for(i=l;i<=10;i+)fprintf(fp,"%d%fn",i,sqrt(double)i);printf("nSucceed!n");/*found*/Fclose(fp);printf("nThe data in file:n");/*found*/if(fp=fopen(myfile3.tex,"r")=NULL)return 0;fscanf(fp,"%d%f",&n,&
8、x);while(!feof(fp)printf("%d%fn",n,x);fscanf(fp,"%d%f",&n,&x);fclose(fp);return 1;)main()char fname="myfile3.txt"fun(fname);)二、程序改错题#include<stdio.h>#include<stdlib.h>void fun(int n,int*a)int i,j,p,t;for(j=0;j<n-l;j+)p=j;/*und*/for(i=j+l;i<n;i+
9、)if(ap>ai)/*字*不found*不 不*不*/p=i;if(P;=j)t=aj;aj=ap;ap=t;)void putarr(int n,int*z)int i;for(i=1;i<=n;i+,z+)printf("%4d",*z);if(!(i%10)printf("n");printf("n");main()int aa20=9,3,0,4,19,5,6,8,10,7),n=ll;printf("nnBefore sorting%d numbers:n",n);putarr(n,aa);
10、printf("nAfter sorting%d numbers:n",n);putarr(n,aa);fun(n,aa);第4套题一、程序填空题#include<stdio.h>#include<stdlib.h>int fun(char source,char*target)/*found*/if(fs=fopen(source,"r")=NULL)if(ft=fopen(target,"w")=NULL)FILEreturn 0;return 0;char ch;printf("nThe dat
11、a in file:n");ch=fgetc(fs);/*found*/putchar(ch);/*字*found*不*/ch=fgetc(fs);)fclose(fs);fclose(ft);printf("nn");return 1;while(!feof(fs)fputc(ch,ft);二、程序改错题#include<stdio.h>void fun(long s,long*t)int d;long sl=l;*t=0;while(s>0)d=s%10;/*亭*亭 found*/*t=d*sl+*t;si*=10;/*found*/)mai
12、n()if(d%2=0)s/=10;long s,t;printf("nPlease enter s:");scanf("%ld",&s);fun(s,&t);printf("The result is:%ldn",t);第 5 套题一、程序填空题#include<stdio.h>#include<stdlib.h>#define N 8typedef stiuct list int data;struct list*next;SLIST;void fun(SLIST*h,int x)SLIST
13、*p,*q,*s;s=(SLIST*)maHoc(sizeof(SLIST);/*found*/s->data=x;q=h;p=h->next;while(p!=NULL&&x>p->data)/*字 不*fou nd*/q=p;p=p->next;s->next=p;/*found*/q->next=s;)SLIST*creatlist(int*a)SLIST*h,*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;i<N;i+)q=(SLIST*)malloc(sizeof
14、(SLIST);q->data=ail;p->next=q;p=q;)p->next=0;return h;)void outlist(SLIST*h)SLIST*p;p=h->next;if(p=NULL)printf("nThe list is NULL!n");else printf("nHead");do printf("->%d",p->data);p=p->next;printf("->Endn");)二、程序改错题 while(p!=NULL);#inc
15、lude<stdio.h>long fun(long num)long k=l;do k*=num%10;/*found*/Num/=10;while(num);return(k);)main()long n;printf("nPlease enter a number:")printf("n%ldn",fun(n);)第 6 套题一、程序填空题scanf("%ld",&n)#include<stdio.h>#include<stdlib.h>#define N 8typedef struc
16、t list int data;struct list*next;SLIST;void fun(SLIST*p)SLIST 九,*s;t=p->next;s=p;while(t->next!=NULL)s=t;/*found*/t=t->next;)/*found*/printf("%d",t->data);s->next=NULL;/*fou nd*不/free(t);SLIST*creatlist(int*a)SLIST*h,*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;i<
17、N;i+)q=(SLIST*)malloc(sizeof(SLIST);q->data=ai;p->next=q;p=q;)p->next=O;return h;void outlist(SLIST*h)SLIST*p;p=h->next;if(p=NULL)printf("nThe list is NULL!n");else printf("nHead");do printf("->%d",p->data);p=p->next;printf("->Endn");)二
18、、程序改错题 while(p!=NULL);#include<stdio.h>/*fk)und*/fun(char"*a)if(*a)fun(a+l);/*字 *f)und*不萃*/printf("%c",*a);main()char s10="abcd"printf("处理前字符串二%sn处理后字符串二",s);fun(s);printf("n");)第 7 套题、程序填空题p->next=O;return h;#include<stdio.h>#include<st
19、dlib.h>#define N 8typedef struct list int data;struct list*next;SLIST;void fun(SLIST*h)SLIST*p,*q;p=h->next;if(p!=NULL)q=p->next;while(q!=NULL)if(p->data=q->data)p->next=q->next;/*found*/free(q);/*found*/q=p->next;)elsep=q;/*found*/q=q->next;)SLIST*creatlist(int*a)SLIST*h,
20、*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;i<N;i+)q=(SLIST*)malloc(sizeof(SLIST);q->data=ai;p->next=q;p=q;二、程序改错题#include<stdio.h>#define N 20void fun(int a,int n)int i,j,t,p;for(j=0;j<n-1;j+)/*tound*字*亭*/P=j;for(i=j+l;i<n;i+)if(ai<ap)/*found*/P=i;t=ap;ap=aj;aj=t;)m
21、ain()int aN=9,6,8,3,-l,i,m=5;printf("排序前的数据:");for(i=0;i<m;i+)printf("%d",ai);printf("n");fun(a,m);printf("排序后的数据:");for(i=0;i<m;i+)printf("%d",ai);printf("n");第8套题一、程序填空题#include<stdio.h>#include<stdlib.h>#define N 8typed
22、ef struct list int data;struct list*next;SLIST;SLIST*creatlist(char*);void outlist(SLIST*);int fun(SLIST*h,char ch)SLIST*p;int n=0;p=h->next;while(p!=NULL)n+;/*found*不*/if(p->data=ch)return n;else p=p->next;)return 0;main()SLIST*head;int k;char ch;charaM=m,/p r gaTw,,k,T,d ;head=creatlist(a
23、);outlist(head);printf("Enter a letter:");scanf("%c",&ch);/*found*/k=fun(head,ch);if(k=0)printf("nNot found!n");else printf("The sequence number is:%dn",k);SLIST*creatlist(char*a)SLIST*h,*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;i<N;i+)q=(SLI
24、ST*)malloc(sizeof(SLIST);q->data=aij;p->next=q;p=q;)p->next=0;return h;)void outlist(SLIST*h)SLIST*p;p=h->next;if(p=NULL)printf("nThe list is NULL!n");else printf("nHead");do printf("->%c",p->data);p=p->next;while(p!=NULL);printf("->Endn&quo
25、t;);)二、程序改错题#include<string.h>#include<stdio.h>#include<ctype.h>fun(char*p)int i,t;char c80;/*字 found*不*/for(i=0,t=0;pi;i+)if(!isspace(*(p+i)ct+=pi;/*found*/ct=0;strcpy(p,c);)main()char c,s80;int i=0;printf("Input a string:");c=getchar();while(c!=#)si=c;i+;c=getchar();si=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二级 语言 题库 答案
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内