08092C语言选修上机考试温习题.docx

上传人:b****5 文档编号:4482081 上传时间:2022-12-01 格式:DOCX 页数:13 大小:17.62KB
下载 相关 举报
08092C语言选修上机考试温习题.docx_第1页
第1页 / 共13页
08092C语言选修上机考试温习题.docx_第2页
第2页 / 共13页
08092C语言选修上机考试温习题.docx_第3页
第3页 / 共13页
08092C语言选修上机考试温习题.docx_第4页
第4页 / 共13页
08092C语言选修上机考试温习题.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

08092C语言选修上机考试温习题.docx

《08092C语言选修上机考试温习题.docx》由会员分享,可在线阅读,更多相关《08092C语言选修上机考试温习题.docx(13页珍藏版)》请在冰豆网上搜索。

08092C语言选修上机考试温习题.docx

08092C语言选修上机考试温习题

一、单项选择题

二、改错题(典型题型)

一、在考生文件夹下,给定程序的功能是:

从低位开始掏出长整型变量s中奇数位上的数,依次组成一个新数放在t中。

例如,当s中的数为:

7654321时,t中的数为:

7531。

请修改并运行该程序,然后将源程序文件上传。

#include<>

main()

{longs,t,sl=10;

system(“CLS”);

printf("\nPleaseenters:

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

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

t=s/10;

while(s>0)

{s=s/100;

t=s%10*sl+t;

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

sl=sl*100;

}

printf("Theresultis:

%ld\n",t);

}

二、在考生文件夹下,给定程序的功能是:

求一维数组a中的值为偶数的元素之和。

例如,当一维数组a中的元素为:

10,4,2,7,3,12,5,34,5,9,程序的输出应为:

Theresultis:

62

请修改并运行该程序,然后将源程序文件提交。

#include<>

#include<>

main()

{inta[10]={10,4,2,7,3,12,5,34,5,9},i,s;

system(“CLS”);

s=0;

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

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

if(i%2==0)s=s+a[i];

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

print("Theresultis:

%d\n",s);

}

3、在考生文件夹下,给定程序的功能是:

求一维数组a中值为偶数的元素之和。

例如,当一维数组a中的元素为:

10,4,2,7,3,12,5,34,5,9,程序的输出应为:

Theresultis:

62。

请修改并运行该程序,然后将源程序文件提交。

#include<>

sum(intarr[],intn)

{inti,s;

system(“CLS”);

s=0;

for(i=0;i

if(arr[i]%2==0)

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

s=s+i;

return(s);

}

main()

{inta[10]={10,4,2,7,3,12,5,34,5,9},i,s;

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

s=sum(a,2);

printf("Theresultis:

%d\n",s);

}

4、在考生文件夹下,给定程序的功能是:

求一维数组a中的最大元素及其下标。

例如,当一维数组a中的元素为:

1,4,2,7,3,12,5,34,5,9,程序的输出应为:

Themaxis:

34,posis:

7。

请修改并运行该程序,然后将源程序文件提交。

#include<>

#include<>

main()

{inta[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos;

system(“CLS”);

max=a[0];pos=0;

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

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

if(max>a[i])

{max=a[i];

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

i=pos;

}

printf("Themaxis:

%d,posis:

%d\n",max,pos);

}

五、在考生文件夹下,给定程序的功能是:

先将在字符串s中的字符按逆序寄存到t串中,然后把s中的字符按正序连接到t串的后面。

例如:

当s中的字符串为:

"ABCDE"时,那么t中的字符串应为:

"EDCBAABCDE"。

请修改并运行该程序,然后将源程序文件提交。

#include<>

#include<>

main()

{chars[80],t[80];

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

inti;

system(“CLS”);

printf("\nPleaseenterstrings:

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

sl=strlen(s);

for(i=0;i

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

t[i]=s[sl-i];

for(i=0;i

t[sl+i]=s[i];

t[2*sl]=’\0’;

printf("Theresultis:

%s\n",t);

}

六、在考生文件夹下,给定程序的功能是:

输出100~200之间既不能被3整除也不能被7整除的整数并统计这些整数的个数,要求每行输出8个数。

请修改并运行该程序,然后将源程序文件提交。

#include<>

#include<>

#include<>

#include<>

main()

{inti;

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

intn;

system(“CLS”);

for(i=100;i<=200;i++)

{

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

if(i%3==0&&i%7==0)

{if(n%8==0)printf("\n");

printf("%6d",i);

n++;

}

}

printf("\nNumbersare:

%d\n",n);}

7、在考生文件夹下,给定程序的功能是:

求一维数组a中所有元素的平均值。

例如,当一维数组a中的元素为:

10,4,2,7,3,12,5,34,5,9,6,8程序的输出应为:

Theeverageis:

请修改并运行该程序,然后将源程序文件提交。

#include<>

#include<>

floataverage(a,n)

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

inta,n;

{

intj;floataver;

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

floats;

for(j=0;j

s+=a[j];

aver=s/n;

return(aver);

}

main()

{inta[12]={10,4,2,7,3,12,5,34,5,9,6,8};

system(“CLS”);

printf("Theaverageis:

%.2f\n",average(a,12));

}

三、程序填空题

一、在考生文件夹下,给定程序的功能是:

把数组a(大小为M)中前M-1个元素中的最大值放入a的最后一个元素中。

#include<>

#defineM11

main()

{inta[M],i;

system(“CLS”);

for(i=0;i

scanf("%d",&a[i]);

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

___

(1)___=a[0];

for(i=1;i

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

if(___

(2)___)

a[M-1]=a[i];

printf("Maxis%d\n",a[M-1]);

}

 

二、在考生文件夹下,给定程序的功能是:

m!

求Cmn=——————之值。

n!

*(m-n)!

例如,当m=12,n=2时,程序的输出应为:

Cmnis:

66。

#include<>

longintfun(intx)

{longints=1;inti;

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

s*=i;

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

____

(1)____;

}

main()

{longintm=12,n=2,s1,s2,s3;

system(“CLS”);

s1=fun(m);

s2=fun(n);

s3=fun(m-n);

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

printf("Cmnis:

%ld",____

(2)____);

}

3、在考生文件夹下,给定程序的功能是:

计算正整数num的列位上的数字之和。

例如,假设输入:

252,那么输出应该是:

9。

假设输入:

202,那么输出应该是:

4。

#include<>

#include<>

main()

{

intnum,k;

clrscr();

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

___

(1)___;

printf("\Pleaseenteranumber:

");

scanf("%d",&num);

do

{

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

k=___

(2)___;

num/=10;

}while(num);

printf("\n%d\n",k);

}

4、在考生文件夹下,给定程序的功能是:

求两个正整数[m,n]之间所有既能被3整除也能被7整除的整数之和。

例如:

m=1,n=1000,那么程序的输出结果应为:

Sumis:

23688。

#include<>

#include<>

longintfun(x,y)

intx,y;

{inti,t;

longints=0;

if(x>y){t=x;x=y;y=t;}

for(i=x;i<=y;i++)

if(i%3==0&&i%7==0)

s+=i;

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

____

(1)____;

}

main()

{intm=1,n=1000;

system(“CLS”);

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

printf("Sumis:

%ld",____

(2)____);

}

五、在考生文件夹下,给定程序的功能是:

从键盘上输入假设干个整数并将这些整数寄存在数组x中,统计计算出平均值,当输入负数时终止。

例如,若是从键盘上输入:

1234-8,那么程序的输出应为:

Output:

ave=

#include<>

main()

{floatx[1000],sum=,ave,a;

intn=0,i;

system(“CLS”);

printf("Enterdigit:

\n");scanf("%f",&a);

while(a>=&&n<1000)

{

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

sum+=___

(1)___;x[n]=a;

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

___

(2)___;

scanf("%f",&a);

}

ave=sum/n;

printf("Output:

\n");

printf("ave=%.2f\n",ave);

}

六、在考生文件夹下,给定程序的功能是:

求一维数组a中非素数之和。

例如:

若是数组a的元素为:

2,3,5,7,8,9,10,11,12,13,15,17,那么程序的输出应为:

Sumis:

54。

#include<>

#include<>

#include<>

main()

{inta[12]={2,3,5,7,8,9,10,11,12,13,15,17},i,j,k,s;

system(“CLS”);

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

____

(1)____;

for(i=0;i<12;i++)

{

k=sqrt(a[i]);

for(j=2;j<=k;j++)

if(a[i]%j==0)break;

if(j<=k)

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

s=s+____

(2)____;

}

printf("Sumis:

%d\n",s);

}

四、编程题

一、在考生文件夹下,给定程序的功能是:

将两个两位数的正整数a、b归并形成一个整数放在c中。

归并的方式是:

将a数的十位和个位数依次放在c数的千位和十位上,b数的十位和个位数依次放在c数的百位和个位上。

例如,当a=45,b=12。

挪用该函数后,c=4152。

部份源程序存在文件中。

请在VC++环境中打开该程序文件,在fun()函数中的/*******begin********/与/********end*********/之间填入你编写的假设干语句。

main()函数中的最后一行和main()函数后面的程序学生没必要阅读,但不要进行任何改动,也不要改动其它位置的任何内容。

保留、运行并调试程序,最后将源程序文件上传。

#include<>

#include<>

longfun(inta,intb)

{longc;

/***********begin***********/

 

/***********end************/

returnc;

}

main()

{inta,b;longc;

system(“CLS”);

printf("Inputa,b:

");scanf("%d,%d",&a,&b);

c=fun(a,b);

printf("Theresultis:

%ld\n",c);

}

二、在考生文件夹下,要求程序的功能是:

将字符串1的第1,3,5,7,9,......位置的字符复制到字符串2并输出。

例如,当字符串1为"ThisIsacProgram",那么字符串2为"hsIrga"

#include<>

#include<>

voidfun(charstr1[],charstr2[])

{

/***********begin***********/

 

/************end************/

}

main()

{charstr1[80]="ThisIsacProgram",str2[80];

system(“CLS”);

printf("Stringis:

%s\n",str1);

fun(str1,str2);

printf("Resultis:

%s\n",str2);

}

3、在考生文件夹下,要求程序的功能是:

将字符串中的所有字符ch(ch中寄存一小写字母)都替换成相应的大写字母,其余的不变;并输出。

例如,当字符串为"ThisIsacProgram",ch的值为’a’时,输出结果应为:

"ThisIsAcProgrAm"

#include<>

#include<>

voidfun(charstr1[],charch)

{

/***********begin***********/

 

/************end************/

}

 

main()

{charstr1[80]="ThisIsacProgram";

system(“CLS”);

printf("Stringis:

%s\n",str1);

fun(str1,’a’);

printf("Resultis:

%s\n",str1);

}

4、在考生文件夹下,要求程序的功能是:

求一维数组a中所有元素的平均值。

部份源程序存在文件中,请将计算结果存入变量av中。

#include""

#include""

#include""

#defineN20

main()

{inta[N]={1,20,8,14,7,12,2,19,19,15,13,14,20,10,16,20,7,6,12,12};

doubleav;

FILE*f;

/***********begin***********/

 

/************end************/

printf("Aver=%f\n",av);

f=fopen("","w");

fprintf(f,"Average=%.2f\n",av);

fclose(f);

}

五、在考生目录下,要求程序的功能是:

按下面的公式求s的近似值:

11111

s=1+——+——+——+——+……+———

2*23*34*45*5n*n

部份源程序存在文件中,n的值由键盘输入。

#include""

#include""

#include""

doublefun(intn)

{

/***********begin***********/

 

/************end************/

}

main()

{doubles;

intn;

system(“CLS”);

printf("Enters:

\n");

scanf("%d",&n);

s=fun(n);

printf("s=%.3f\n",s);

}

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

当前位置:首页 > 高中教育 > 高中教育

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

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