全国计算机C语言二级上机试题10套6170.docx

上传人:b****5 文档编号:8011837 上传时间:2023-01-27 格式:DOCX 页数:28 大小:20KB
下载 相关 举报
全国计算机C语言二级上机试题10套6170.docx_第1页
第1页 / 共28页
全国计算机C语言二级上机试题10套6170.docx_第2页
第2页 / 共28页
全国计算机C语言二级上机试题10套6170.docx_第3页
第3页 / 共28页
全国计算机C语言二级上机试题10套6170.docx_第4页
第4页 / 共28页
全国计算机C语言二级上机试题10套6170.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

全国计算机C语言二级上机试题10套6170.docx

《全国计算机C语言二级上机试题10套6170.docx》由会员分享,可在线阅读,更多相关《全国计算机C语言二级上机试题10套6170.docx(28页珍藏版)》请在冰豆网上搜索。

全国计算机C语言二级上机试题10套6170.docx

全国计算机C语言二级上机试题10套6170

61

#include

#defineN5

typedefstructstudent{

longsno;

charname[10];

floatscore[3];

}STU;

voidfun(char*filename)

{FILE*fp;inti,j;

STUs[N],t;

/**********found**********/

fp=fopen(filename,__1__);

fread(s,sizeof(STU),N,fp);

fclose(fp);

for(i=0;i

for(j=i+1;j

/**********found**********/

if(s[i].sno__2__s[j].sno)

{t=s[i];s[i]=s[j];s[j]=t;}

fp=fopen(filename,"wb");

/**********found**********/

__3__(s,sizeof(STU),N,fp);

fclose(fp);

}

main()

{STUt[N]={{10005,"ZhangSan",95,80,88},{10003,"LiSi",85,70,78},

{10002,"CaoKai",75,60,88},{10004,"FangFang",90,82,87},

{10001,"MaChao",91,92,77}},ss[N];

inti,j;FILE*fp;

fp=fopen("student.dat","wb");

fwrite(t,sizeof(STU),5,fp);

fclose(fp);

printf("\n\nTheoriginaldata:

\n\n");

for(j=0;j

{printf("\nNo:

%ldName:

%-8sScores:

",t[j].sno,t[j].name);

for(i=0;i<3;i++)printf("%6.2f",t[j].score[i]);

printf("\n");

}

fun("student.dat");

printf("\n\nThedataaftersorting:

\n\n");

fp=fopen("student.dat","rb");

fread(ss,sizeof(STU),5,fp);

fclose(fp);

for(j=0;j

{printf("\nNo:

%ldName:

%-8sScores:

",ss[j].sno,ss[j].name);

for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);

printf("\n");

}

}

00000000000000000000000000

#include

#include

voidfun(chars[],intn)

{

chara[80],*p;

inti;

/**********found***********/

s=p;

for(i=0;i

do

{a[i]=*p;

i++;

}

/**********found***********/

while(*p++)

a[i]=0;

strcpy(s,a);

}

main()

{intn;chars[80];

printf("\nEnterastring:

");gets(s);

printf("\nThestring\"%s\"\n",s);

printf("\nEntern(numberof*):

");scanf("%d",&n);

fun(s,n);

printf("\nThestringafterinsert:

\"%s\"\n",s);

}

0000000000000000000

#include

#defineN50

#defineM11

voidfun(int*a,int*b)

{

}

doublernd()

{statict=29,c=217,m=1024,r=0;

r=(r*t+c)%m;return((double)r/m);

}

NONO(intd[M])

{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。

*/

FILE*wf;inti;

wf=fopen("C:

\\WEXAM\\YS240001\\out.dat","w");

for(i=0;i<10;i++)fprintf(wf,"%4d---%4d:

%4d\n",i*10,i*10+9,d[i]);

fprintf(wf,"Over100:

%4d\n",d[10]);

fclose(wf);

}

main()

{intage[N],i,d[M];

for(i=0;i

printf("Theoriginaldata:

\n");

for(i=0;i

"%4d\n":

"%4d",age[i]);

printf("\n\n");

fun(age,d);

for(i=0;i<10;i++)printf("%4d---%4d:

%4d\n",i*10,i*10+9,d[i]);

printf("Over100:

%4d\n",d[10]);

NONO(d);

}

62

#include

#defineN5

typedefstructstudent{

longsno;

charname[10];

floatscore[3];

}STU;

voidfun(char*filename,STUn)

{FILE*fp;

/**********found**********/

fp=fopen(__1__,"rb+");

/**********found**********/

fseek(__2__,-1L*sizeof(STU),SEEK_END);

/**********found**********/

fwrite(&n,sizeof(STU),1,__3__);

fclose(fp);

}

main()

{STUt[N]={{10001,"MaChao",91,92,77},{10002,"CaoKai",75,60,88},

{10003,"LiSi",85,70,78},{10004,"FangFang",90,82,87},

{10005,"ZhangSan",95,80,88}};

STUn={10006,"ZhaoSi",55,70,68},ss[N];

inti,j;FILE*fp;

fp=fopen("student.dat","wb");

fwrite(t,sizeof(STU),N,fp);

fclose(fp);

fp=fopen("student.dat","rb");

fread(ss,sizeof(STU),N,fp);

fclose(fp);

printf("\nTheoriginaldata:

\n\n");

for(j=0;j

{printf("\nNo:

%ldName:

%-8sScores:

",ss[j].sno,ss[j].name);

for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);

printf("\n");

}

fun("student.dat",n);

printf("\nThedataaftermodifing:

\n\n");

fp=fopen("student.dat","rb");

fread(ss,sizeof(STU),N,fp);

fclose(fp);

for(j=0;j

{printf("\nNo:

%ldName:

%-8sScores:

",ss[j].sno,ss[j].name);

for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);

printf("\n");

}

}

0000000000000000000

#include

#include

typedefstructaa

{intdata;

structaa*next;

}NODE;

NODE*Creatlink(intn,intm)

{NODE*h=NULL,*p,*s;

inti;

/**********found***********/

p=(NODE)malloc(sizeof(NODE));

h=p;

p->next=NULL;

for(i=1;i<=n;i++)

{s=(NODE*)malloc(sizeof(NODE));

s->data=rand()%m;s->next=p->next;

p->next=s;p=p->next;

}

/**********found***********/

returnp;

}

outlink(NODE*h)

{NODE*p;

p=h->next;

printf("\n\nTHELIST:

\n\nHEAD");

while(p)

{printf("->%d",p->data);

p=p->next;

}

printf("\n");

}

main()

{NODE*head;

head=Creatlink(8,22);

outlink(head);

}

000000000000000000000000

#include

#include

#defineN80

intfun(char*s)

{

}

NONO()

{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。

*/

FILE*rf,*wf;inti,num;charline[N],*p;

rf=fopen("C:

\\WEXAM\\YS240001\\in.dat","r");

wf=fopen("C:

\\WEXAM\\YS240001\\out.dat","w");

for(i=0;i<10;i++){

fgets(line,N,rf);

p=strchr(line,'\n');

if(p!

=NULL)*p=0;

num=fun(line);

fprintf(wf,"%d\n",num);

}

fclose(rf);fclose(wf);

}

main()

{charline[N];intnum=0;

printf("Enterastring:

\n");gets(line);

num=fun(line);

printf("Thenumberofwordis:

%d\n\n",num);

NONO();

}

63

#include

#include

charfun(charch)

{

/**********found**********/

if((ch>='a')___1___(ch<='z'))

returnch-'a'+'A';

if(isupper(ch))

/**********found**********/

returnch+'a'-___2___;

/**********found**********/

return___3___;

}

main()

{charc1,c2;

printf("\nTheresult:

\n");

c1='w';c2=fun(c1);

printf("c1=%cc2=%c\n",c1,c2);

c1='W';c2=fun(c1);

printf("c1=%cc2=%c\n",c1,c2);

c1='8';c2=fun(c1);

printf("c1=%cc2=%c\n",c1,c2);

}

000000000000000000000000

#include

#defineM4

/**************found**************/

voidfun(inta)

{inti,j,k,m;

printf("Enter4number:

");

for(i=0;i

printf("\n\nTheresult:

\n\n");

for(i=M;i>0;i--)

{k=a[M-1];

for(j=M-1;j>0;j--)

/**************found**************/

aa[j]=a[j-1];

a[0]=k;

for(m=0;m

printf("\n");

}

}

main()

{inta[M];

fun(a);printf("\n\n");

}

00000000000000000000

#include

intfun(intn)

{

}

NONO()

{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。

*/

FILE*rf,*wf;inti,n,sum;

rf=fopen("C:

\\WEXAM\\YS240001\\in.dat","r");

wf=fopen("C:

\\WEXAM\\YS240001\\out.dat","w");

for(i=0;i<10;i++){

fscanf(rf,"%d",&n);

sum=fun(n);

fprintf(wf,"%d=%d\n",n,sum);

}

fclose(rf);fclose(wf);

}

main()

{intn,sum;

printf("Inputn:

");scanf("%d",&n);

sum=fun(n);

printf("sum=%d\n",sum);

NONO();

}

64

#include

#include

#include

char*fun(char*s)

{inti,j,k,n;char*p,*t;

n=strlen(s)+1;

t=(char*)malloc(n*sizeof(char));

p=(char*)malloc(n*sizeof(char));

j=0;k=0;

for(i=0;i

{if(((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))){

/**********found**********/

t[j]=__1__;j++;}

else

{p[k]=s[i];k++;}

}

/**********found**********/

for(i=0;i<__2__;i++)t[j+i]=p[i];

/**********found**********/

t[j+k]=__3__;

returnt;

}

main()

{chars[80];

printf("Pleaseinput:

");scanf("%s",s);

printf("\nTheresultis:

%s\n",fun(s));

}

00000000000000000000000

#include

#include

intfun(char*s,char*t1,char*t2,char*w)

{

inti;char*p,*r,*a;

strcpy(w,s);

/************found************/

while(w)

{p=w;r=t1;

while(*r)

/************found************/

IF(*r==*p)

{r++;p++;}

elsebreak;

if(*r=='\0')a=w;

w++;

}

r=t2;

while(*r){*a=*r;a++;r++;}

}

main()

{

chars[100],t1[100],t2[100],w[100];

printf("\nPleaseenterstringS:

");scanf("%s",s);

printf("\nPleaseentersubstringt1:

");scanf("%s",t1);

printf("\nPleaseentersubstringt2:

");scanf("%s",t2);

if(strlen(t1)==strlen(t2))

{fun(s,t1,t2,w);

printf("\nTheresultis:

%s\n",w);

}

elseprintf("\nError:

strlen(t1)!

=strlen(t2)\n");

}

0000000000000000000000

#include

#include

voidfun(char*s,chart[])

{

}

NONO()

{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。

*/

chars[100],t[100];

FILE*rf,*wf;

inti;

rf=fopen("C:

\\WEXAM\\YS240001\\in.dat","r");

wf=fopen("C:

\\WEXAM\\YS240001\\out.dat","w");

for(i=0;i<10;i++){

fscanf(rf,"%s",s);

fun(s,t);

fprintf(wf,"%s\n",t);

}

fclose(rf);

fclose(wf);

}

main()

{

chars[100],t[100];

printf("\nPleaseenterstringS:

");scanf("%s",s);

fun(s,t);

printf("\nTheresultis:

%s\n",t);

NONO();

}

65

#include

#include

structstudent{

longsno;

charname[10];

floatscore[3];

};

/**********found**********/

__1__fun(structstudent*a)

{inti;

a->sno=10002;

strcpy(a->name,"LiSi");

/**********found**********/

for(i=0;i<3;i++)__2__+=1;

/**********found**********/

return__3__;

}

main()

{structstudents={10001,"ZhangSan",95,80,88},*t;

inti;

printf("\n\nTheoriginaldata:

\n");

printf("\nNo:

%ldName:

%s\nScores:

",s.sno,s.name);

for(i=0;i<3;i++)printf("%6.2f",s.score[i]);

printf("\n");

t=fun(&s);

printf("\nThedataaftermodified:

\n");

printf("\nNo:

%ldName:

%s\nScores:

",t->sno,t->name);

for(i=0;i<3;i++)printf("%6.2f",t->score[i]);

printf("\n");

}

0000000000000

#include

#include

#defineN5

#defineM81

/**********found**********/

fun(char(*sq)[M])

{inti;char*sp;

sp=sq[0];

for(i=0;i

if(strlen(sp)

sp=sq[i];

/**********found**********/

returnsq;

}

main()

{charstr[N][M],*longest;inti;

printf("Enter%dlines:

\n",N);

for(i=0;i

printf("\nTheNstrin

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1