安徽省二级c语言上机试题Word文档格式.docx
《安徽省二级c语言上机试题Word文档格式.docx》由会员分享,可在线阅读,更多相关《安徽省二级c语言上机试题Word文档格式.docx(28页珍藏版)》请在冰点文库上搜索。
将在字符串t中而为在字符串s中的字符顺序存放到一个新的字符u中。
如当s=12345,t=2468时,u中的字符为“68”
#include<
string.h>
chars[80]="
12345"
t[80]="
2468"
u[80];
inti,j,p,len1,len2;
p=____;
/*$BLANK1$*/
len1=strlen(t);
len2=strlen(s);
for(i=0;
i<
len1;
i++)
for(j=0;
len2;
if(t[i]==s[j])break;
if(j>
=len2)
{
u[p]=____;
/*$BLANK2$*/
p++;
}
u[p]=____;
/*$BLANK3$*/
%s\n"
u);
t[i]
\0
3:
程序设计:
[三色球问题]若一个口袋中方有12的球,3的红色,3的白色,6个黑色。
从中任取8个球,求共有多少种不同的颜色搭配。
如1红,3白,4黑。
等。
输入格式:
count=123
voidPRINT(intn)
FILE*out;
count=%d\n"
n);
if((out=fopen("
K:
\\24000101\\RESULT.DAT"
"
w+"
))!
=NULL)
fprintf(out,"
count=%dp"
fclose(out);
intr,w,b;
intn=0;
for(r=0;
r<
=3;
r++)
for(w=0,w<
=3,w++)
for(b=0;
b<
=6;
b++)
if(r+w+b==8)n++;
PRINT(n);
1:
改错
inti,j;
i=1;
while(i<
6)
for(j=1;
6-i;
printf("
"
);
j=1;
/*$ERROR1$*/
while(j>
=1)
{
%d"
/*$ERROR2$*/
--j;
printf("
/n"
/*$ERROR3$*/
i++;
J=I;
Printf(“%d”,j)
Printf(“\n”)
程序填空
floatsum(floatq)
intN=1;
floatSN=0;
while(SN__q)/*$BLANK1$*/
SN=SN+1.0*(N+1)/N;
____;
returnSN;
floatq;
Inputq:
"
scanf("
%f"
&
q);
%f\n"
_____);
<
=
N++
sum(q))
3程序设计
voidPRINT(longsum)
sum=%ld\n"
sum);
sum=%lds"
Iongsum=0;
intI,n,flag;
for(i=100;
2011;
{flag=0;
n=i;
do{
if(n%10==5)
elsen=n/10;
}while(n>
0);
if(flag&
&
i%3==0)
sum+=i
PRINT(sum);
#defineN4
#defineM5
{
inti,j;
floatscore,firstscore,max;
for(i=1;
=M;
\nPleaseinputscoreofcourseno%d:
scanf("
firstscore);
/*$ERROR1$*/
max=&
firstscore;
/*$ERROR2$*/
for(j=2;
=N;
j++)
scanf("
&
score);
if(score>
max)
score=max;
\nThemaxscoreofcourseno%dis:
%f"
i,max);
答案;
2:
intfun(intn)
inti,sum=0;
for(i=2;
_____;
i++)/*$BLANK1$*/
if(_____)sum=sum+i;
returnsum;
intn;
Inputn:
n);
intgetMaxFromArray(inta[],intn)
inti,max;
max=1;
/*$ERROR1$*/
n;
if(a[i]>
a[max])
max=i;
returni;
/*$ERROR2$*/
inta[10]={13,1,-5,4,9,0,-8,7,-6,2};
intmax;
max=getMaxFromArray(a);
max=%d,address=%d\n"
a[max],max);
charstr[80],*ch;
intflag=1;
Pleaseinputastring:
\n"
gets(str);
ch=____;
while(*ch)
if(*ch=='
'
)flag=1;
else
if(flag==____&
*ch>
='
a'
&
*ch<
z'
)/*$BLANK2$*/
*ch=*ch-32;
flag=0;
____;
str);
程序设计
intsum(intn)
inti,s;
s=1;
=n;
s=s+i;
returns;
inti,n;
longs;
\nPleaseinputn:
s=0;
s=sum(i);
\nTheresultis%ld\n"
s);
voidfun(ints[],int*n)
inta,b,c,i;
for(i=100;
=999;
a=______;
b=i/10%10;
c=i%10;
if(a+b+c==9)
s[*n]=i;
______;
/*$BLANK2$*/
}
ints[50],n=0,i;
fun(_____);
%d"
s[i]);
3;
structcar
{charid[12];
intscore;
};
inti,n=0;
carc[6]={{"
A-QQ111"
8},/*$ERROR1$*/
{"
A-TT222"
12},
B-WJ333"
C-LC444"
5},
F-PC555"
6},
B-MY666"
12}};
id\tscore\n"
i=0;
6)
if(score>
=12)/*$ERROR2$*/
%s\t%d\n"
c[i].id,c[i].score);
n--;
i++;
n=%d\n"
ctype.h>
chars[80];
inti=0,a[5]={0};
gets(____);
while(s[i]!
=_____)/*$BLANK2$*/
switch(toupper(s[i]))
case'
A'
:
a[0]++;
break;
E'
a[1]++;
I'
a[2]++;
O'
a[3]++;
U'
a[4]++;
______;
5;
a[i]);
longf(intn)
if(n=1||n=2)/*$ERROR1$*/
return1;
else
returnf(n-1)-f(n-2);
longm;
if(n>
0)
m=f(n);
%ld\n"
m);
elseprintf("
Dataerror\n"
voidfun(chars[])
for(i=0,j=0;
s[i]!
=_____;
if(s[i]<
'
0'
||s[i]>
9'
)
s[j++]=s[i];
s[j]=____;
charstr[80];
Inputastring:
gets(_____);
fun(str);
puts(str);
intsort(inta[],intlenth)
inti,t;
if(lenth<
return-1;
lenth/2;
t=a[0];
a[i]=a[lenth-i-1];
a[lenth-i-1]=t;
/*$ERROR2$*/
inta[10]={1,2,3,4,5,6,7,8,9,10};
inti,nReturn;
\nTheascendingarrayis:
10;
%4d"
nReturn=sort(10);
if(nReturn==0)
\nThedescendingarrayis:
for(i=0;
else
error!
inta[10]={34,-5,12,50,88,62,1,-70,-20,0};
inti,j,temp;
for(i=0;
9;
9-i;
if(_____)/*$BLANK1$*/
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=_____;
}
=9;
%5d"