福建c语言考试之填空.docx

上传人:b****1 文档编号:11171647 上传时间:2023-05-29 格式:DOCX 页数:32 大小:27.07KB
下载 相关 举报
福建c语言考试之填空.docx_第1页
第1页 / 共32页
福建c语言考试之填空.docx_第2页
第2页 / 共32页
福建c语言考试之填空.docx_第3页
第3页 / 共32页
福建c语言考试之填空.docx_第4页
第4页 / 共32页
福建c语言考试之填空.docx_第5页
第5页 / 共32页
福建c语言考试之填空.docx_第6页
第6页 / 共32页
福建c语言考试之填空.docx_第7页
第7页 / 共32页
福建c语言考试之填空.docx_第8页
第8页 / 共32页
福建c语言考试之填空.docx_第9页
第9页 / 共32页
福建c语言考试之填空.docx_第10页
第10页 / 共32页
福建c语言考试之填空.docx_第11页
第11页 / 共32页
福建c语言考试之填空.docx_第12页
第12页 / 共32页
福建c语言考试之填空.docx_第13页
第13页 / 共32页
福建c语言考试之填空.docx_第14页
第14页 / 共32页
福建c语言考试之填空.docx_第15页
第15页 / 共32页
福建c语言考试之填空.docx_第16页
第16页 / 共32页
福建c语言考试之填空.docx_第17页
第17页 / 共32页
福建c语言考试之填空.docx_第18页
第18页 / 共32页
福建c语言考试之填空.docx_第19页
第19页 / 共32页
福建c语言考试之填空.docx_第20页
第20页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

福建c语言考试之填空.docx

《福建c语言考试之填空.docx》由会员分享,可在线阅读,更多相关《福建c语言考试之填空.docx(32页珍藏版)》请在冰点文库上搜索。

福建c语言考试之填空.docx

福建c语言考试之填空

填空题

1)程序ccon491.c的功能是:

对输入的一个正整数,计算其所含因子3的个数。

例如:

输入:

54

输出:

3

#include

#include

voidmain()

{inti,n,n3;

/**//**/

printf("Inputainteger:

");

scanf("%d",/**//**/);

while(n%3==0)

{n3++;

/**//**/

}

printf("\nn3:

%d",n3);

getch();

}

ccon491.c

/**/n3=0;i=3;/**/

/**/&n/**/

/**/n=n/i;/**/

2)程序ccon492.c中的p_factor(intx)函数,实现输出正整数x的所有真因子(除了1和x以外),若无真因子则提示为素数。

例如:

x为13,则输出:

13isaprimenumber!

x为16,则输出:

248

#include

#include

voidp_factor(intx)

{inti,mark;

/**//**/;

for(i=2;i<=x/2;i++)

if(/**//**/==0)

{

mark=1;

printf("%2d",i);

}

if(!

mark)

printf("%disaprimenumber!

",x);

printf("\n");

}

voidmain()

{inta;

printf("Inputanumber:

");

scanf("%d",&a);

p_factor(/**//**/);

getch();

}

ccon492.c

/**/mark=0/**/;

/**/x%i/**/

/**/a/**/

 

3)程序ccon501.c,输出如下图形

1

11

121

1331

14641

15101051

1615201561

172135352171

#include

#include

voidmain()

{inti,j;

/**//**/

a[0]=1;

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

{printf("\t");

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

{if(/**//**/)

b[j]=1;

else

b[j]=a[j-1]+a[j];

printf("%3d",/**//**/);

}

printf("\n");

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

a[j]=b[j];

}

getch();

}

ccon501.c

/**/inta[8],b[8];/**/

/**/j==0||j==i/**/

/**/b[j]/**/

4)程序ccon502.c中的phalanx(inta[][],intn)函数,根据参数n(

),输出类似如下的方阵(n=6)

123456

24681012

345678

468101214

5678910

6810121416

#include

#include

#defineM10

voidphalanx(inta[][M],intn)

{int/**//**/,j;

for(i=0;i

for(j=0;j

{

if(i%2==0)

a[i][j]=i+1+j;

else

a[i][j]=/**//**/;

}

printf("Array(n=%d)is:

\n",n);

for(i=0;i

{

for(j=0;j

printf("%3d",a[i][j]);

printf("\n");

}

}

voidmain()

{

inta[M][M];

intn;

printf("Inputn(2<=n<=10):

");

scanf("%d",&n);

phalanx(/**//**/,n);

getch();

}

ccon502.c

/**/i/**/

/**/i+2*j+1/**/

/**/a/**/

5)程序ccon511.c的功能是:

以每行5个数的形式输出100到200之间所有个位数为奇数且十位数为偶数或0的整数

#include

#include

voidmain()

{inti,gw,sw,count;

/**//**/

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

{

sw=i/10;

/**//**/

if(gw%2!

=0&&sw%2==0)

{if(/**//**/)

printf("\n");

printf("%5d",i);

count++;

}

}

getch();

}

ccon511.c

/**/count=0;/**/

/**/gw=i%10;/**/

/**/count%5==0/**/

6)将程序ccon512.c填写完整,使函数encrypt(char*s)实现将字符串中所有奇数位置(注:

字符串首字符为第1位)上的数字用比其小1的数字替换。

如,数字1用0替换,数字2用1替换、数字3用2替换…数字0用9替换(非数字则不替换)。

例如:

输入:

ky123456+D009876

输出:

ky022446+D908866

#include

#include

#include

voidencrypt(char*s)

{inti=1;

char*p=s;

while(*p)

{if(i%2!

=0)

{

if(/**//**/)

*p=*p-1;

elseif(*p=='0')

*p='9';

}

p++;

/**//**/;

}

}

voidmain()

{charstr[100];

printf("Inputstring:

\n");

gets(str);

encrypt(str);

printf("\nNowstringis:

\n");

puts(str);

getch();

}

ccon512.c

/**/*p>='1'&&*p<='9'/**/

/**/i++/**/;

7)程序ccon521.c,输出符合以下条件的3位整数的个数:

第一位和第三位数字不相同,且各位数的和为15

#include

#include

voidmain()

{inti,j,k,count;

/**//**/

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

for(j=0;j<=9;j++)

for(k=0;k<=9;k++)

{if(/**//**/)

count++;

}

printf("\ncount=%d",count);

getch();

}

ccon521.c

/**/count=0;/**/

/**/i!

=k&&i+j+k==15/**/

 

8)将程序ccon522.c填写完整,使函数r_shift(inta[])实现将数组a各元素循环右移1个位置,最后一个元素存到首位。

例如:

数组a元素为:

13579108642

循环右移后为:

21357910864

#include

#include

#defineN10

voidr_shift(inta[])

{inti,temp;

temp=a[N-1];

for(i=N-1;/**//**/;i--)

a[i]=/**//**/;

a[0]=temp;

}

voidmain()

{intarr[N]={1,3,5,7,9,10,8,6,4,2},i;

printf("Originalarrayis:

\n");

for(i=0;i

printf("%d",arr[i]);

r_shift(/**//**/);

printf("\nNowarrayis:

\n");

for(i=0;i

printf("%d",arr[i]);

getch();

}

ccon522.c

/**/i>=1/**/

/**/a[i-1]/**/

/**/arr/**/

9)程序ccon531.c的功能是:

用选择排序法对输入的10个整数按从大到小排序并输出结果:

例如:

输入:

2934841657

输出:

9876544321

#include

#include

voidmain()

{inti,j,k;

/**//**/

inta[10];

printf("Enter10integers:

");

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

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

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

{max=a[i];

k=i;

for(j=i+1;/**//**/;j++)

if(a[j]>max)

{max=a[j];

/**//**/

}

if(k!

=i)

{temp=a[i];

a[i]=a[k];

a[k]=temp;

}

}

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

printf("%d",a[i]);

getch();

}

ccon531.c

/**/intmax,temp;/**/

/**/j<10/**/

/**/k=j;/**/

10)将程序ccon532.c填写完整,使函数convert(

inta[][])输出数组a表示的N*N矩阵的转置矩阵

例如:

5*5矩阵

12345

1112131415

2122232425

3132333435

4142434445

转置后:

111213141

212223242

313233343

414243444

515253545

#include

#include

#defineN5

voidconvert(inta[][N])

{inti,/**//**/,temp;

for(i=0;/**//**/;i++)

for(j=i+1;j

{temp=a[i][j];

a[i][j]=/**//**/;

a[j][i]=temp;

}

}

voidmain()

{inti,j;

intarr[N][N];

for(i=0;i

for(j=0;j

arr[i][j]=10*i+j+1;

printf("Originalarray:

\n");

for(i=0;i

{for(j=0;j

printf("%3d",arr[i][j]);

printf("\n");

}

convert(arr);

printf("Convertedarray:

\n");

for(i=0;i

{for(j=0;j

printf("%3d",arr[i][j]);

printf("\n");

}

getch();

}

ccon532.c

/**/j/**/

/**/i

/**/a[j][i]/**/

 

11)补充程序ccon591.c,计算

的值

#include

voidmain()

{longintk;

inti;

k=/**//**/;

for(i=1;/**//**/;i+=3)

/**//**/

printf("\nk=%ld",k);

getch();

}

ccon591.c

/**/1/**/

/**/i<=25/**/

/**/k*=i;/**/

12)补充程序ccon592.c,求以下分数序列前15项之和。

#include

#include

voidmain()

{

intn,x,y,t;

floatsum;

/**//**/;

x=2;

y=1;

for(n=1;/**//**/;n++)

{

sum+=1.0*x/y;

t=x;

x=x+y;

y=/**//**/;

}

printf("sum=%f",sum);

getch();

}

ccon592.c

/**/sum=0/**/

/**/n<=15/**/

/**/t/**/

13)补充程序ccon601.c,输出100以内能被3整除且个位数字为6的所有正整数。

#include

#include

voidmain()

{inti,k;

for(i=0;/**//**/;i++)

{k=10*i+6;

if(/**//**/)

continue;

printf("%-5d",/**//**/);

}

printf("\n");

getch();

}

ccon601.c

/**/i<10/**/

/**/k%3!

=0/**/

/**/k/**/

14)补充程序ccon602.c,使chang_w()函数对字符串中的元音字母进行加密,方法是:

‘a’转换成’e’、‘e’转换成’i’、‘i’转换成’o’、‘o’转换成’u’、‘u’转换成’a’,其他字符保持不变。

例如:

输入原文:

Youarewelcome!

输出密文:

Yuaeriwilcumi!

#include

#include

#include

voidchange_w(/**//**/)

{

inti=0;

while(str[i])

{

switch(str[i])

{case'a':

str[i]='e';break;

case'e':

/**//**/;

case'i':

str[i]='o';break;

case'o':

str[i]='u';break;

case'u':

str[i]='a';

}

/**//**/;

}

}

voidmain()

{

charsrc[80],tag[80];

printf("Pleaseinputsourcestring:

");

gets(src);

strcpy(tag,src);

change_w(tag);

printf("\nThesourcestring:

%s\n",src);

printf("Thetargetstring:

%s\n",tag);

getch();

}

ccon602.c

/**/charstr[]/**/

/**/str[i]='i';break;/**/

/**/i++/**/

15)补充程序ccon611.c,逐一计算方阵x和y中主对角线上相应位置元素的和,并依此存入z数组)。

例如:

方阵x为:

19587

31154

2301

方阵y为:

116223

4516

378109

#include

#include

#defineSIZE3

voidmain()

{intx[SIZE][SIZE]={19,58,7,31,15,4,23,0,1};

inty[SIZE][SIZE]={11,62,23,4,5,16,37,8,109};

intz[SIZE],i;

for(i=0;/**//**/;i++)

z[i]=/**//**/;

for(i=0;i

printf("%-5d",/**//**/);

printf("\n");

getch();

}

ccon611.c

/**/i

/**/x[i][i]+y[i][i]/**/

/**/z[i]/**/

16)补充程序ccon612.c,使sort()函数用选择法对数组a中n个元素按从小到大排序。

#include

#include

#defineN12

voidsort(/**//**/)

{

inti,j,mark,t;

for(i=0;i

{

mark=i;

for(/**//**/;j

if(a[j]

mark=j;

if(mark!

=i)

{

t=a[mark];

a[mark]=/**//**/;

a[i]=t;

}

}

}

voidmain()

{

inta[N]={12,0,7,-5,2,16,23,8,-3,10,19,5};

inti;

sort(a);

printf("Thesortednumbers:

\n");

for(i=0;i

printf("%d",a[i]);

printf("\n");

getch();

}

ccon612.c

/**/inta[]/**/

/**/j=i+1/**/

/**/a[i]/**/

17)补充程序ccon621.c,计算[1,100]区间内所有奇数之和及所有偶数之和。

#include

#include

voidmain()

{intasum,bsum,a,i;

asum=bsum=/**//**/;

for(i=1;/**//**/;i+=2)

{asum+=i;

a=/**//**/;

bsum+=a;

}

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

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

getch();

}

ccon621.c

/**/0/**/

/**/i<100/**/

/**/i+1/**/

18)补充程序ccon622.c,统计字符串str中字母’a’和字母’A’的总个数。

#include

#include

#include

inttotal(charstr[])

{

intn;

char*p=str;

/**//**/;

while(*p)

{

if(/**//**/||*p=='A')

n++;

/**//**/;

}

returnn;

}

voidmain()

{

charstr[255];

printf("Enterastring:

");

gets(str);

printf("Totalof'a'and'A'is:

%d\n",total(str));

getch();

}

ccon622.c

/**/n=0/**/

/**/*p=='a'/**/

/**/p++/**/

19)补充程序ccon631.c,对一组整数,求它们十位上的数的和

#include

#include

#defineN10

voidmain()

{intsum,i;

inta[N]={45,69,123,78,90,102,60,300,51,999};

sum=/**//**/;

for(i=0;/**//**/;i++)

sum=sum+(/**//**/);

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

getch();

}

ccon631.c

/**/0/**/

/**/i

/**/a[i]/10%10/**/

20)补充程序ccon632.c,对输入的一个正整数,从低位到高位依次取出各位上为偶数的数字,组成一个新的整数。

例如:

输入:

367281

输出:

826

#include

#include

unsignedlongfun(unsignedlongx)

{

unsignedlongk=0;

int/**//**/;

while(x)

{

t=x%10;

if(t%2==0)

k=k*10+/**//**/;

x=x/10;

}

return/**//**/;

}

voidmain()

{

unsignedlongx=-1;

while(x<0||x>99999999)

{

printf("Pleaseinputx(0

");

scanf("%ld",&x);

}

printf("\nTheresultis:

%ld\n",fun(x));

getch();

}

ccon632.c

/**/t/**/

/**/t/**/

/**/k/**/

21.将程序Ccon541.c填写完整,输出所有各位数字之和等于18的三位数正整数。

#include

#include

voidmain()

{inti,a1,a2,a3;

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2