第一范文网 - 专业文章范例文档资料分享平台

计算机二级试题2014 - 6 (4)

来源:用户分享 时间:2020-06-22 本文由生人勿近 分享 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

2014年6月

到大排序。

#include #include #define N 12

void sort(/**/ /**/) {

int i, j, mark, t;

for( i = 0; i < N-1; i++ ) {

mark = i;

for(/**/ /**/; j< N; j++) if(a[j] < a[mark]) mark=j; if( mark != i ) {

t= a[mark] ;

a[mark]=/**/ /**/; a[i] =t; } } }

void main() {

int a[N]={12,0,7,-5,2,16,23,8,-3,10,19,5}; int i; sort(a);

printf(\ for(i=0;i

printf(\ \ printf(\ getch(); }

(7)补充程序ccon621.c,计算[1,100]区间内所有奇数之和及所有偶数之和。 #include #include void main()

{ int asum,bsum,a,i;

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

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

a=/**/ /**/;

16

bsum+=a; }

printf(\ printf(\ getch(); }

(8)补充程序ccon622.c,统计字符串str中字母?a?和字母?A?的总个数。 #include #include #include int total(char str[] ) {

int n;

char *p= str; /**/ /**/; while(*p) {

if(/**/ /**/ || *p=='A') n++; /**/ /**/; }

return n; }

void main() {

char str[255];

printf(\ gets(str);

printf(\of 'a' and 'A' is: %d\\n\ getch(); }

(9)补充程序ccon631.c, 对一组整数,求它们十位上的数的和 #include #include #define N 10 void main() { int sum, i; int

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

2014年6月

sum=/**/ /**/; 5.8x2?1.3yfun(x,y)? for(i=0; /**/ /**/; i++) 21.6y?4.5x?1.8 sum=sum+(/**/ /**/);

例如:fun(2.250, 1.280)=3.335 printf(\

getch(); #include } #include #include (10)补充程序ccon632.c,对输入的一个正整double fun(float x,float y) 数,从低位到高位依次取出各位上为偶数的{ /**/ 数字,组成一个新的整数。例如: 输入:367281 输出:826 #include #include /**/ unsigned long fun(unsigned long x) } { unsigned long k=0; void main() int /**/ /**/; { float x,y; while(x) printf(\ { scanf(\ t=x; printf(\ if(t%2== 0 ) = %.3lf\\n\ k=k*10 + /**/ /**/; getch(); x=x/10 ; }

2) 打开程序cprog592.c,完成函 }

数int fun(int a[N], int b[N]), 实现: return /**/ /**/;

逐一比较数组a和b中对应位置上的}

元素(即:a[0]与b[0], a[1]与b[1],?), void main()

分别统计a中大于、等于和小于b中{

对应位置元素的个数。若大于的个数 unsigned long x=-1;

比小于的个数多,函数的返回值为1, while(x<0 || x>99999999)

若小于的个数比大于的个数多,函数 {

返回值为-1, 否则函数返回值为0。 printf(\input

x(0 scanf(\#include } #define N 10 printf(\int fun(int a[N],int b[N]) getch(); { /**/ }

编程题

1) 打开程序cprog591.c,对double fun(float x,float y)的函数编程,使其 计算:

17

2014年6月

/**/ }

void main()

{ int a[N]={45,12,47,86,9,2,43,18,100,20}; int b[N]={51,32,47,16,7,12,33,18,99,21}; switch(fun(a,b))

{ case 1:printf(\a is larger than array b.\

case 0:printf(\b.\

case -1:printf(\a is smaller than array b.\ }

printf(\ getch();}??

3) 打开程序cprog601.c,对double fun(float x)的函数编程,使其计算:

fun(x)?ex?0.7cosx?1.52

例如:fun(0.450)=0.359 #include #include #include double fun(float x) { /**/

/**/ }

void main() { float x;

printf(\ scanf(\

printf(\ getch(); }

4) 打开程序cprog602.c,完成函数fun(char *str, char arr[ ]), 实现:

18

将str所指字符串中下标为奇数且ASCII码值为偶数的字符依次放入数组arr中。

例如, str所指字符串为”AbCdEegH”, 则数组arr的内容则为”bdH”。 #include #include

void fun(char *str,char arr[]) { /**/

/**/ }

void main()

{ char str[100],arr[100];

printf(\enter string str: \

scanf(\ fun(str,arr);

printf(\ getch(); }??

5) 打开程序cprog611.c,对double fun(float x)的函数编程,使其计算:

?1.63x?1.27x?1fun(x)???1.5x?1 ??sin(x?1.05)x?1#include #include #include double fun(float x) { /**/

2014年6月

/**/ }

void main()

{ printf(\ printf(\ printf(\ getch(); }

6) 打开程序cprog612.c,完成函数fun(int a, int b),实现:

将两位正整数a、b合并成一个数存在c中。合并的规则是:将a的十位数和个位数依次放在c的百位数和十位数,b的十位和个位数依次放在c的个位数和千位数。并将c作为函数值返回。

如:a=36, b=41, 则合并后c=1364 #include #include int fun(int a,int b) { /**/

/**/ }

void main() { int a,b,c; do

{ printf(\

scanf(\

}while((a<10||a>=100) || (b<10||b>=100)); c=fun(a,b);

printf(\ getch();}??

7) 打开程序cprog621.c,对double fun(float x)的函数编程,使其计算:

19

?x2?1.5?0.7x?3fun(x)????3x?3 ???11.3?x2x?3#include #include #include double fun(float x) { /**/

/**/ }

void main()

{ printf(\;

printf(\

printf(\ getch(); }

8) 打开程序cprog622.c完成函数fun(int n),根据以下公式计算前n项之和并返回。 (1?n?20)

12358(n?1)0?1?1?2?2?3?3?5?5?8?aa?an(n?2)?a(n?1)a(n?1)?an其中,an?an?2?an?1 如:n=6, sum=4.126 #include #include #define N 20 float fun(int n) { /**/

2014年6月

/**/ }

void main() { int n;

float sum; do

{ printf(\ scanf(\ }while(n<1 || n>20); sum=fun(n);

printf(\ getch();}

9) 打开程序cprog631.c,对double fun(float x,float y)的函数编程,使其计算:

?x?yx?yfun(x,y)???0x?y ??x?yx?y#include

#include

double fun(float x,float y) { /**/

/**/ }

void main() { float x,y;

printf(\ scanf(\ printf(\= %.3lf\\n\ getch(); }

10) 打开程序cprog632.c,完成函数fun(int a[N][N],int k), 将二维数组a左上半三角(含对角线)各元素的值加上k。

20

?123?如:数组a为??456?

? , 若

??789???678k=5, 则a变为???9106??

??1289??#include #include #define N 3

void fun(int a[N][N],int k) { /**/

/**/ }

void main() { int a[N][N] = {{1,2,3},{4,5,6},{7,8,9}}; int k,i,j;

printf(\array is:\\n\

for(i=0; i

for(j=0;j

printf(\ printf(\ }

printf(\ scanf(\ fun(a,k);

printf(\ for(i=0; i

{ for(j=0;j

getch();}

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新幼儿教育计算机二级试题2014 - 6 (4)全文阅读和word下载服务。

计算机二级试题2014 - 6 (4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/wenku/1095732.html(转载请注明文章来源)
热门推荐
Copyright © 2018-2022 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top