资源预览内容
第1页 / 共8页
第2页 / 共8页
第3页 / 共8页
第4页 / 共8页
第5页 / 共8页
第6页 / 共8页
第7页 / 共8页
第8页 / 共8页
亲,该文档总共8页全部预览完了,如果喜欢就下载吧!
资源描述
20122012 计算机二级计算机二级 C C 语言答案语言答案1. 给定程序 modi.c 中函数 fun 的功能是:首先将大写字母转换为对应小写字母;若小写字母为 au,则将其转换为其后的第 5 个字母;若小写字母为 vz,使其值减 21。转换后的小写字母作为函数值返回。例如,若形参是字母 A,则转换为小写字母 f;若形参是字母 W,则转换为小写字母 b。#include #include char fun(char c) if( c=A for (k=10;k#include int fun( int n ,int *value ) int d,s,i;/*found*/d=1; s=0;for(i=1; i=8);sum=fun( n,printf(“nnThe result:n value=%d sum=%dnn“,v,sum);4. 给定程序 modi.c 中函数 fun 的功能是:根据整型形参 m,计算如下公式的值。例如,若 m 中的值为:5,则应输出:1.463611。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!#include #include double fun ( int m ) double y = 1.0 ;int i;/*found*/for(i = 2 ; i #include #include /*found*/double fun(int n) double A=1;int i;/*found*/for (i=2;i#include #include #includevoid fun (char *s,char *t) int i,sl;sl=strlen(s);/*found*/for (i=0;i#include #include void fun(int m,int k)int aa20,i;for (i=0;m;i+)/*found*/aai=m%k;m/=k;/*found*/for(i=i-1;i=0;i-)printf(“%d“,aai);main()int b,n;system(“cls“);printf(“nPlease enter a number and a base:n“);scanf(“%d %d“,fun(n,b);printf(“n“);8. 给定程序 modi.c 中函数 fun 的功能是:将 s 所指字符串中最后一次出现的、t1 所指子串替换成 t2 所指子串,所形成的新串放在w 所指的数组中。在此处,要求 t1 和 t2 所指字符串的长度相同。例如,当 s 所指字符串中的内容为:“abcdabfabc“,t1 所指子串中的内容为:“ab“,t2 所指子串中的内容为:“99“时, 结果,在 w 所指的数组中的内容应为:“abcdabf99c“。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!#include #include #include #include int fun (char *s, char *t1, char *t2 , char *w)int i; char *p , *r, *a;strcpy( w, s );/*found*/while ( *w ) p = w; r = t1;while ( *r )/*found*/if ( *r = *p ) r+; p+; else break;if ( *r = 0 ) a = w;w+;r = t2;while ( *r ) *a = *r; a+; r+; main()char s100, t1100, t2100, w100;system(“cls“);printf(“nPlease enter string S:“); scanf(“%s“, s);printf(“nPlease enter substring t1:“); scanf(“%s“, t1);printf(“nPlease enter substring t2:“); scanf(“%s“, t2);if ( strlen(t1)=strlen(t2) )
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号