全国计算机C语言二级上机试题10套8190.docx
《全国计算机C语言二级上机试题10套8190.docx》由会员分享,可在线阅读,更多相关《全国计算机C语言二级上机试题10套8190.docx(31页珍藏版)》请在冰豆网上搜索。
全国计算机C语言二级上机试题10套8190
81
#include
fun(intx)
{intn,s1,s2,s3,t;
/**********found**********/
n=__1__;
t=100;
/**********found**********/
while(t<=__2__)
{s1=t%10;s2=(t/10)%10;s3=t/100;
if(s1+s2+s3==15)
{printf("%d",t);
n++;
}
/**********found**********/
__3__;
}
returnn;
}
main()
{intx=-1;
while(x>999||x<0)
{printf("Pleaseinput(0");scanf("%d",&x);}
printf("\nTheresultis:
%d\n",fun(x));
}
0000000000000000000
#include
#include
voidfun(char*s,char*t)
{
/************found************/
inti;
sl=strlen(s);
for(i=0;i/************found************/
t[i]=s[sl-i];
for(i=0;it[sl+i]=s[i];
t[2*sl]='\0';
}
main()
{chars[100],t[100];
printf("\nPleaseenterstrings:
");scanf("%s",s);
fun(s,t);
printf("Theresultis:
%s\n",t);
}
000000000000000000
#include
voidfun(inta,intb,long*c)
{
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。
*/
FILE*rf,*wf;
inti,a,b;longc;
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,%d",&a,&b);
fun(a,b,&c);
fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c);
}
fclose(rf);
fclose(wf);
}
main()/*主函数*/
{inta,b;longc;
printf("Inputa,b:
");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("Theresultis:
%ld\n",c);
NONO();
}
82
#include
#include
#defineN8
typedefstructlist
{intdata;
structlist*next;
}SLIST;
voidfun(SLIST*h,intx)
{SLIST*p,*q,*s;
s=(SLIST*)malloc(sizeof(SLIST));
/**********found**********/
s->data=___1___;
q=h;
p=h->next;
while(p!
=NULL&&x>p->data){
/**********found**********/
q=___2___;
p=p->next;
}
s->next=p;
/**********found**********/
q->next=___3___;
}
SLIST*creatlist(int*a)
{SLIST*h,*p,*q;inti;
h=p=(SLIST*)malloc(sizeof(SLIST));
for(i=0;i{q=(SLIST*)malloc(sizeof(SLIST));
q->data=a[i];p->next=q;p=q;
}
p->next=0;
returnh;
}
voidoutlist(SLIST*h)
{SLIST*p;
p=h->next;
if(p==NULL)printf("\nThelistisNULL!
\n");
else
{printf("\nHead");
do{printf("->%d",p->data);p=p->next;}while(p!
=NULL);
printf("->End\n");
}
}
main()
{SLIST*head;intx;
inta[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("\nThelistbeforeinserting:
\n");outlist(head);
printf("\nEnteranumber:
");scanf("%d",&x);
fun(head,x);
printf("\nThelistafterinserting:
\n");outlist(head);
}
00000000000000000000000
#include
longfun(longnum)
{
/************found************/
longk;
do
{k*=num%10;
/************found************/
num\=10;
}while(num);
return(k);
}
main()
{longn;
printf("\nPleaseenteranumber:
");scanf("%ld",&n);
printf("\n%ld\n",fun(n));
}
00000000000000000000
#include
floatfun(float*a,intn)
{
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。
*/
FILE*fp,*wf;
inti,j;
floataver,score[5];
fp=fopen("C:
\\WEXAM\\YS240001\\in.dat","r");
wf=fopen("C:
\\WEXAM\\YS240001\\out.dat","w");
for(i=0;i<10;i++){
for(j=0;j<5;j++)fscanf(fp,"%f,",&score[j]);
aver=fun(score,5);
fprintf(wf,"%5.2f\n",aver);
}
fclose(fp);
fclose(wf);
}
main()
{floatscore[30]={90.5,72,80,61.5,55},aver;
aver=fun(score,5);
printf("\nAveragescoreis:
%5.2f\n",aver);
NONO();
}
83
#include
#include
#defineN5
#defineM8
intfun(char(*ss)[M],char*t)
{inti;
/**********found**********/
for(i=0;i<__1__;i++)
/**********found**********/
if(strcmp(ss[i],t)==0)return__2__;
return-1;
}
main()
{charch[N][M]={"if","while","switch","int","for"},t[M];
intn,i;
printf("\nTheoriginalstring\n\n");
for(i=0;iprintf("\nEnterastringforsearch:
");gets(t);
n=fun(ch,t);
/**********found**********/
if(n==__3__)printf("\nDon'tfound!
\n");
elseprintf("\nThepositionis%d.\n",n);
}
00000000000000000000
#include
fun(int*b)
{intk,a1,a2,i=0;
for(k=10;k<=55;k++){
/************found************/
a2=k/1O;
a1=k-a2*10;
if((k%3==0&&a2==5)||(k%3==0&&a1==5))
{b[i]=k;i++;}
}
/************found************/
returnk;
}
main()
{inta[100],k,m;
m=fun(a);
printf("Theresultis:
\n");
for(k=0;k}
00000000000000000000000000
#include
voidfun(char*a)
{
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。
*/
FILE*in,*out;
inti;chars[81];
in=fopen("C:
\\WEXAM\\YS240001\\in.dat","r");
out=fopen("C:
\\WEXAM\\YS240001\\out.dat","w");
for(i=0;i<10;i++){
fscanf(in,"%s",s);
fun(s);
fprintf(out,"%s\n",s);
}
fclose(in);
fclose(out);
}
main()
{chars[81];
printf("Enterastring:
\n");gets(s);
fun(s);
printf("Thestringafterdeleted:
\n");puts(s);
NONO();
}
84
#include
#include
#include
voidWriteText(FILE*);
voidReadText(FILE*);
main()
{FILE*fp;
if((fp=fopen("myfile4.txt","w"))==NULL)
{printf("openfail!
!
\n");exit(0);}
WriteText(fp);
fclose(fp);
if((fp=fopen("myfile4.txt","r"))==NULL)
{printf("openfail!
!
\n");exit(0);}
ReadText(fp);
fclose(fp);
}
/**********found**********/
voidWriteText(FILE___1___)
{charstr[81];
printf("\nEnterstringwith-1toend:
\n");
gets(str);
while(strcmp(str,"-1")!
=0){
/**********found**********/
fputs(___2___,fw);fputs("\n",fw);
gets(str);
}
}
voidReadText(FILE*fr)
{charstr[81];
printf("\nReadfileandoutputtoscreen:
\n");
fgets(str,81,fr);
while(!
feof(fr)){
/**********found**********/
printf("%s",___3___);
fgets(str,81,fr);
}
}
0000000000000000000000
#include
/************found************/
voidfun(longs,longt)
{longsl=10;
*t=s%10;
while(s>0)
{s=s/100;
*t=s%10*sl+*t;
/************found************/
sl=sl*100;
}
}
main()
{longs,t;
printf("\nPleaseenters:
");scanf("%ld",&s);
fun(s,&t);
printf("Theresultis:
%ld\n",t);
}
000000000000000000000
#include
voidfun(inta,intb,long*c)
{
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。
*/
FILE*rf,*wf;
inti,a,b;longc;
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,%d",&a,&b);
fun(a,b,&c);
fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c);
}
fclose(rf);
fclose(wf);
}
main()
{inta,b;longc;
printf("Inputa,b:
");
scanf("%d,%d",&a,&b);
fun(a,b,&c);
printf("Theresultis:
%ld\n",c);
NONO();
}
85
#include
/**********found**********/
___1___fun(charch)
{
/**********found**********/
if(ch>='0'&&___2___)
/**********found**********/
return'9'-(ch-___3___);
returnch;
}
main()
{charc1,c2;
printf("\nTheresult:
\n");
c1='2';c2=fun(c1);
printf("c1=%cc2=%c\n",c1,c2);
c1='8';c2=fun(c1);
printf("c1=%cc2=%c\n",c1,c2);
c1='a';c2=fun(c1);
printf("c1=%cc2=%c\n",c1,c2);
}
00000000000000000
#include
voidfun(char*p,char*b)
{inti,k=0;
while(*p)
{i=1;
while(i<=3&&*p){
/**********found**********/
b[k]=p;
k++;p++;i++;
}
if(*p)
{
/**********found**********/
b[k++]="";
}
}
b[k]='\0';
}
main()
{chara[80],b[80];
printf("Enterastring:
");gets(a);
printf("Theoriginalstring:
");puts(a);
fun(a,b);
printf("\nThestringafterinsertspace:
");puts(b);printf("\n\n");
}
0000000000000000
#include
#include
#defineN8
structslist
{doubles;
structslist*next;
};
typedefstructslistSTREC;
doublefun(STREC*h)
{
}
STREC*creat(double*s)
{STREC*h,*p,*q;inti=0;
h=p=(STREC*)malloc(sizeof(STREC));p->s=0;
while(i{q=(STREC*)malloc(sizeof(STREC));
q->s=s[i];i++;p->next=q;p=q;
}
p->next=0;
returnh;
}
outlist(STREC*h)
{STREC*p;
p=h->next;printf("head");
do
{printf("->%4.1f",p->s);p=p->next;}
while(p!
=0);
printf("\n\n");
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。
*/
FILE*in,*out;
inti,j;doubles[N],ave;
STREC*h;
in=fopen("C:
\\WEXAM\\YS240001\\in.dat","r");
out=fopen("C:
\\WEXAM\\YS240001\\out.dat","w");
for(i=0;i<10;i++){
for(j=0;jh=creat(s);
ave=fun(h);
fprintf(out,"%6.3lf\n",ave);
}
fclose(in);
fclose(out);
}
main()
{doubles[N]={85,76,69,85,91,72,64,87},ave;
STREC*h;
h=creat(s);outlist(h);
ave=fun(h);
printf("ave=%6.3f\n",ave);
NONO();
}
86
#include
doublefun(doublex,intn)
{doublef,t;inti;
f=1.0;
/**********found**********/
t=___1___;
/**********found**********/
for(i=___2___;i{
/**********found**********/
t*=x/___3___;
f+=t;
}
returnf;
}
main()
{doublex,y;
x=2.5;
y=fun(x,12);
printf("\nTheresultis:
\n");
printf("x=%-12.6fy=%-12.6f\n",x,y);
}
00000000000000000000000000
#include
#defineN100
intfun(int*s,intn)
{inti,j,k,a,b,c;
j=0;
for(i=100;i/**************found**************/
k=n;
a=k%10;k/=10;
b=k%10;k/=10;
/**************found**************/
c=k%10
if(a==b&&a==c)s[j++]=i;
}
returnj;
}
main()
{inta[N],n,num=0,i;
do
{printf("\nEntern(<=1000):
");scanf("%d",&n);}
while(n>1000);
num=fun(a,n);
printf("\n\nTheresult:
\n");
for(i=0;iprintf("\n\n");
}
00000000000000000000000000
#include
#include
doublefun(doublex[10])
{
}
NONO()
{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。
*/
FILE*rf,*wf;int